Evaluating Models
Accuracy is the easiest metric to understand, and one of the easiest to be misled by. This lesson shows exactly how, using a deliberately imbalanced dataset, and introduces the metrics that actually reveal what's going on.
When accuracy lies
make_classification(weights=[0.95, 0.05]) generates a synthetic dataset with a 95/5 class imbalance. A model that lazily predicts "class 0" for everything, without learning anything real, would still score around 95% accuracy here, high accuracy alone doesn't prove the model is actually useful.
Metrics that reveal the truth
- The confusion matrix breaks predictions into a 2x2 grid: true negatives, false positives, false negatives, and true positives (in that reading order for binary classification). It's the raw material every other classification metric is computed from.
- Precision answers "of everything the model flagged as positive, how much was actually positive?", important when false alarms are costly.
- Recall answers "of everything that was actually positive, how much did the model catch?", important when missing a positive case is costly (like a real fraud case slipping through).
A model can have high accuracy and terrible recall on the minority class simultaneously, that's exactly the trap this lesson demonstrates.
TIP
There's rarely one "correct" metric, a spam filter (annoying to have false positives) and a cancer screening test (dangerous to have false negatives) should be tuned toward completely different tradeoffs between precision and recall, choosing the right metric for the problem is as important as choosing the right model.