Why accuracy alone can mislead
A model that is right 95% of the time sounds excellent. But if only 10% of cases are positive, a model that always predicts 'negative' is already right 90% of the time. Evaluation is about choosing the metric that matches the cost of each kind of mistake.
The confusion matrix
Imagine a spam filter tested on 1,000 emails, of which 100 are spam.
| Predicted spam | Predicted not spam | |
|---|---|---|
| Actually spam | TP = 80 | FN = 20 |
| Actually not spam | FP = 30 | TN = 870 |
The metrics worked out
| Metric | Formula | Result | Meaning |
|---|---|---|---|
| Accuracy | (TP + TN) ÷ total | 95.0% | Share of all predictions that were right |
| Precision | TP ÷ (TP + FP) | 72.7% | When it says spam, how often is it right? |
| Recall (sensitivity) | TP ÷ (TP + FN) | 80.0% | Of the real spam, how much did it catch? |
| F1 score | 2 × precision × recall ÷ (precision + recall) | 0.76 | One number balancing precision and recall |
| Specificity | TN ÷ (TN + FP) | 96.7% | Of the real non-spam, how much was left alone? |
The accuracy trap: a model that labels every email 'not spam' scores 90% accuracy here yet catches no spam at all, so its recall is 0%.
Which metric to favour
| Situation | Favour | Why |
|---|---|---|
| Missing a case is costly, such as disease screening or fraud | Recall | Better to flag too many than miss real cases |
| False alarms are costly, such as blocking genuine emails | Precision | Avoid disrupting legitimate activity |
| Classes are imbalanced and both errors matter | F1 | Balances the two |
Thresholds and the trade-off
Most models output a probability and you pick a cut-off. Lowering it raises recall and usually lowers precision. An ROC curve or precision-recall curve shows this trade-off across all cut-offs, and the area under the ROC curve summarises overall ranking quality.
Good habits
- Always evaluate on data the model has not seen
- Report several metrics, not one
- Compare with a simple baseline
- Look at errors by segment to find hidden weaknesses
Related: A/B testing basics, Python for data science and portfolio projects.
Building a data career?
Talk to an advisor about data science programmes that fit your background.
Frequently Asked Questions
What is the difference between precision and recall?
Precision asks how many flagged items were truly positive; recall asks how many true positives were caught.
Why can high accuracy be misleading?
With imbalanced data, always predicting the majority class gives high accuracy while missing every positive case.
What is an F1 score?
The harmonic mean of precision and recall, giving one number that balances both.
How do I choose a threshold?
Pick the cut-off that suits the relative cost of false positives and false negatives in your problem.