python-machine-learning-book-2nd-edition
python-machine-learning-book-2nd-edition copied to clipboard
Chapter 4 typo - page 132
Greetings professor Raschka,
Thank you for writing such an amazing book!
On Page 132, I found a small bug in SBS class:
Original:
def transform(self, X): return X[:, self.indices_]
I think the correct code should be:
def transform(self, X): return X[:, self.subsets_[np.argmax(self.scores_)]
The two results seem the same. Do you get different results?
@weishanlee I tried the original code with my project, and always ended up with transform method always transformed the original array into a one column array. The reason is that after fit method has been called, self.indices_ is the score of the last permutation, and what we actually want is the best score across permutations, not the last permutation itself.
Thanks for the note, and sorry for the late response. I somehow missed the notification.
I am not quite sure if I am following the in the code, we have
best = np.argmax(scores)
self.indices_ = subsets[best]
So the transform method should yield the best subset of size k. If you do
def transform(self, X):
return X[:, self.subsets_[np.argmax(self.scores_)]
it would return the best subset regardless of the size (so it won't necessarily be size k) when I see that correctly