handson-ml2 icon indicating copy to clipboard operation
handson-ml2 copied to clipboard

Chap 3, more clarification for Never5Classifier(BaseEstimator)

Open hypntzed78 opened this issue 4 years ago • 2 comments

from sklearn.base import BaseEstimator
class Never5Classifier(BaseEstimator):
    def fit(self, X, y=None):
        pass
    def predict(self, X):
        return np.zeros((len(X), 1), dtype=bool)

I don't understand how this being created. I thought it would predict not-5 class is true, but whereas y_train[1] == 0 , never_5_clf.predict(X_train) is still False for the [1] ? plz explain how this classifier work. Which code represent it can predict the not-5?

image

hypntzed78 avatar Oct 08 '21 16:10 hypntzed78

Thanks for your question.

The Never5Classifier always predicts False, no matter what you give it as input. The goal is to point out that even such a dumb classifier gets over 90% accuracy, and that's just because the dataset is skewed: only 10% of the instances are 5s, so 90% of them are not 5s.

The instance X_train[1] represents a zero (as you can see because y_train[1] == 0). So it's not a 5. Therefore the Never5Classifier is correct when it predicts False, meaning "this is not a 5". Despite being so dumb, the classifier will get it right roughly 90% of the time.

Hope this helps.

ageron avatar Oct 10 '21 01:10 ageron

Thanks for your question.

The Never5Classifier always predicts False, no matter what you give it as input. The goal is to point out that even such a dumb classifier gets over 90% accuracy, and that's just because the dataset is skewed: only 10% of the instances are 5s, so 90% of them are not 5s.

The instance X_train[1] represents a zero (as you can see because y_train[1] == 0). So it's not a 5. Therefore the Never5Classifier is correct when it predicts False, meaning "this is not a 5". Despite being so dumb, the classifier will get it right roughly 90% of the time.

Hope this helps.

@ageron thank you so much, I understand your idea.

hypntzed78 avatar Oct 10 '21 10:10 hypntzed78