python-machine-learning-book-2nd-edition icon indicating copy to clipboard operation
python-machine-learning-book-2nd-edition copied to clipboard

Chapter 4 typo - page 132

Open polishtits opened this issue 6 years ago • 3 comments

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_)]

polishtits avatar Jan 26 '19 06:01 polishtits

The two results seem the same. Do you get different results?

weishanlee avatar Jan 26 '19 10:01 weishanlee

@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.

polishtits avatar Jan 26 '19 15:01 polishtits

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

rasbt avatar Jun 14 '19 11:06 rasbt