<aside> ⚠️ This note serves as a reminder of the book's content, including additional research on the mentioned topics. It is not a substitute for the book. Most images are sourced from the book or referenced.

</aside>

<aside> 🚨 I've noticed that taking notes on this site while reading the book significantly extends the time it takes to finish the book. I've stopped noting everything, as in previous chapters, and instead continue reading by highlighting/hand-writing notes instead. I plan to return to the detailed style when I have more time.

</aside>

<aside> ✊ This book contains 1007 pages of readable content. If you read at a pace of 10 pages per day, it will take you approximately 3.3 months (without missing a day) to finish it. If you aim to complete it in 2 months, you'll need to read at least 17 pages per day.

</aside>

Information

List of notes for this book

<aside> 📔 Jupyter notebook for this chapter: on Github, on Colab, on Kaggle.

</aside>

MNIST

 = 5

y[0] = 5

Training a Binary Classifier

Let’s simplify the problem - “detect only the number 5” ← binary classifier (2 classes, 5 or non-5).

Good to start is stochastic gradient descent (SGD, or stochastic GD) classifier ← [SGDClassifier](<https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDClassifier.html>) ← deals with training instances independently, one at a time ← handling large datasets effeciently, well suited for online training.

from sklearn.linear_model import SGDClassifier

sgd_clf = SGDClassifier(random_state=42)
sgd_clf.fit(X_train, y_train_5)

sgd_clf.predict([some_digit])

Performance Measures

Evaluating a classifier is often significantly trickier than evaluating a regressor!

Measuring Accuracy Using Cross-Validation

Use [cross_val_score()](<https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.cross_val_score.html>) ← use k-folds.

from sklearn.model_selection import cross_val_score
cross_val_score(sgd_clf, X_train, y_train_5, cv=3, scoring="accuracy")

Wow, get 95% accuracy with SGD but it’s good? → Let’s try [DummyClassifier](<https://scikit-learn.org/stable/modules/generated/sklearn.dummy.DummyClassifier.html>) ← classifies every single image in the most frequent class (non-5) and then use cross_val_score → 90% accuracy! Why? It’s because only 10% are 5s! ← If you always guess that an image is not a 5, 90% of the time, you’re right!