Typo on Page 433 #122
baifanhorst
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The desired buckets on page 433 have closed left ends and open right ends. So the option 'right' in torch.bucketize should be set to False. Here is the code:
df_train_norm['model year bucketed'] = torch.bucketize(v, boundaries, right=False)
One can also try the following codes to see how torch.bucketize() works:
test_data = torch.tensor([1.0, 2.5, 3.0, 4.2, 5.1, 6.8, 7.1])
bins = torch.tensor([1.0, 3.0, 5.0, 7.0])
bins_default = torch.bucketize(test_data, bins, right=False)
print(bins_default)
The result is:
tensor([0, 1, 1, 2, 3, 3, 4])
It can be seen that the first entry, 1.0, is put to the first bin. Therefore the right boundary is excluded from this bin. Similary, the third entry 3.0 is put to the second bucket.
Similary, the code on page 434 should be modified as:
df_test_norm['model year bucketed'] = torch.bucketize(v, boundaries, right=False)
By the way, the feature names in my codes do not contain capital letters.
Beta Was this translation helpful? Give feedback.
All reactions