Lesson 17: Evaluating Models Fairly
A model is only as good as its performance on data it has never seen, measured honestly. The most common evaluation mistake is also the simplest: testing on the training data. A model that memorised its training set will score perfectly there and tell you nothing about how it will do in the world. Fair evaluation starts with keeping a test set aside from the very beginning — data the model never trains on and that you never use to make decisions — and reporting the score on that set, once, at the end.
Accuracy — the share of answers that are right — is the first metric most people reach for, and it is often misleading. Imagine a worked example: a model screens photos for a rare fault that appears in only 2 out of every 100 photos. A model that always answers "no fault" scores 98% accuracy and is completely useless. Accuracy hides the failure because the classes are unbalanced. When the classes are uneven, or when one kind of mistake costs more than the other, accuracy is the wrong number to report.
Precision, Recall and the Confusion Matrix
Better metrics start from the confusion matrix: a small table counting true positives, false positives, true negatives and false negatives. Precision asks, of the cases the model flagged, how many were real? Recall asks, of the real cases, how many did the model find? A medical screening test needs high recall — missing a case is costly — even if that means some false alarms. A spam filter needs high precision — wrongly hiding a real message is costly — even if some spam slips through. Which matters more depends on the cost of each mistake, and the honest thing is to report both.
For tasks with more than two classes, the same idea extends: report the accuracy per class, not just the overall figure, so that a model that is perfect on the common class and terrible on a rare one cannot hide. And for any metric, report it on the test set with the size of that set, so a reader can judge how much to trust it: 90% on 20 examples is a much weaker claim than 90% on 2,000.
Baselines and Comparisons
A score means little without a baseline to compare it with. Before celebrating a model, ask what a trivial rule would score: always guessing the most common class, or a simple method from an earlier lesson. If your network barely beats the trivial rule, it has learned almost nothing, however impressive its accuracy sounds. Comparing against a baseline keeps you honest — and it often reveals that the simple approach was the right one all along.
A Baseline for Every Project
Every evaluation should start with the simplest baseline you can think of, and the habit is worth making automatic. For a classification task, the baseline is to always guess the most common class; for a regression task, it is to always predict the average. These baselines are trivially easy to compute, and they set the bar your model must clear. If your network scores 85% accuracy and the most common class is 84% of the data, your model has learned almost nothing, however impressive 85% sounds. If it scores 85% against a baseline of 50%, it has learned a great deal.
Baselines also protect you from fooling yourself during development. It is easy to spend days improving a model from 85% to 86% without noticing that a simple rule already scores 84%. The time would have been better spent on the data: more examples, better labels, or a feature that captures what the model is missing. A baseline is not a low bar to clear and forget; it is a reminder that complexity must earn its keep, every time.
Reporting Uncertainty Honestly
A single accuracy number is a claim about a model, and like any claim it should come with its uncertainty. The score on a test set of 200 examples could easily shift by several points on a different 200, and reporting 87% without saying that is implying a precision the measurement does not have. A confidence interval on the metric, or simply the size of the test set alongside the score, lets the reader judge how much to trust it. This matters most when two models are compared: a gap of one point on a small test set is noise, not a victory, and choosing a model on that basis is choosing at random. Report the number, the size of the test, and the interval — and let the reader see how solid the result really is.
The confusion matrix
Accuracy hides the difference between the two kinds of mistake; the confusion matrix shows them both.
Key Terms
- Test set
- Data kept aside from the start, used once at the end to measure a model honestly.
- Accuracy
- The share of predictions that are correct; misleading when classes are unbalanced.
- Confusion matrix
- A table counting true positives, false positives, true negatives and false negatives.
- Precision
- Of the cases a model flagged, the share that were real.
- Recall
- Of the real cases, the share the model found.
- Baseline
- A simple rule or method used as a comparison point for a model's score.
- Class imbalance
- When one class is much rarer than the others, so accuracy can hide failure.
Discussion Questions
- Why must the test set be kept aside from the very beginning, not just from training?
- A screening test and a spam filter need different trade-offs. What decides which metric matters more in each case?
- If a model scores 99% accuracy, what is the first question you should ask before believing it?
Practice Questions
- Why is testing on the training data unfair?
- In the worked example, why does 'always answer no fault' score 98% accuracy?
- What is precision?
- What is recall?
- Why compare a model against a trivial baseline?
Show answers
- Because a model can memorise its training data and score perfectly there while failing on new examples. The training score measures memory, not learning.
- Because the fault appears in only 2 out of 100 photos, so always saying 'no fault' is right 98 times out of 100. The accuracy hides that the model never finds a single fault.
- Of the cases the model flagged, the share that were real. High precision means few false alarms.
- Of the real cases, the share the model found. High recall means few missed cases.
- Because a score means little on its own: if a simple rule scores nearly as well, the model has learned almost nothing. The baseline shows whether the complexity is earning its keep.