Why Accuracy is Misleading
A spam filter that labels every single email as "not spam" achieves 99% accuracy if only 1% of emails are actually spam. It's also completely useless. Accuracy hides everything interesting when classes are imbalanced or when different types of mistakes have different costs.
For the SVHN digit recognition task, accuracy is more meaningful — 10 balanced classes, and misclassifying a "3" as an "8" is roughly as bad as any other mistake. But even here, the pattern of errors matters: which digits get confused with which?
The Confusion Matrix
A confusion matrix is a grid where rows represent the true class and columns represent the predicted class. Each cell shows how many examples of class X were classified as class Y. The diagonal is correct predictions; everything off-diagonal is a mistake.
The confusion matrix reveals which specific classes are confused with each other — actionable information that a single accuracy number never could.
The Four Outcomes
For any given class (say, "is this a 5?"), every prediction falls into one of four categories:
The model predicted "5" and it was actually a 5. Correct positive.
The model predicted "not 5" and it wasn't a 5. Correct negative.
The model predicted "5" but it was something else. Wrong — a false alarm. Also called Type I error.
The model predicted "not 5" but it was actually a 5. Missed it. Also called Type II error.
Precision, Recall, and F1
Of all the times the model predicted this class, how often was it right? High precision means few false alarms. "When I say it's a 5, I'm usually correct."
Of all the actual examples of this class, how many did the model find? High recall means few misses. "Of all the real 5s, I found most of them."
F1-Score — The Harmonic Mean
The F1-score combines precision and recall into one number. It's the harmonic mean — which penalises large imbalances. A model with precision=1.0 and recall=0.01 gets an F1 of 0.02, not 0.5. This makes F1 a robust single-number summary: you can only get a high F1 if both precision and recall are reasonably high.
Macro vs. Weighted Average
For multi-class problems, you have a precision, recall, and F1 per class. Averaging them:
- Macro average: Simple mean across all classes. Treats each class equally regardless of size.
- Weighted average: Weights each class by its number of examples. More representative when class sizes differ. Standard for imbalanced datasets.
Reading a Classification Report
Train / Validation / Test Split
Evaluating a model on data it trained on is meaningless — it's like grading a student on the same questions used for practice. Proper evaluation requires held-out data:
- Training set: The model sees this data and learns from it. Typically 70–80% of the data.
- Validation set: Used during training to monitor overfitting and tune hyperparameters. The model doesn't train on this, but it's used to make decisions about training — so it's "seen" indirectly.
- Test set: Completely held out. Only used once, at the very end, to report final performance. This is the honest number. If you tune your model based on test set performance, you've contaminated it — it's no longer an unbiased estimate.
Interactive: CNN2 Confusion Matrix
Each row is a true digit; each column is what the model predicted. The bright green diagonal is correct predictions. Off-diagonal cells reveal which digit pairs get confused — hover any cell to inspect. Notice how 3↔5 and 4↔9 are the most common errors, driven by visual similarity.
All four models were evaluated on the same held-out test set (28,796 images). The classification report for CNN2 showed consistently high F1 scores across all 10 digits (0.89–0.96), confirming balanced learning with no catastrophically weak class. The confusion matrix revealed that the most common errors were between visually similar digit pairs: 3↔5, 4↔9, and 8↔6. Overall test accuracy: 92.22% — the headline metric, but the full report told the complete story. See Chapter 8 — Model Results →