r/learnmachinelearning • u/ClickOk5811 • 7d ago
A model that never predicts “positive” gets 95% accuracy: do the arithmetic yourself
A good exercise for anyone starting with classification. Suppose a dataset of 1,000 examples where only 50 are positive (5%), like fraud, a rare disease, or a defect. Compare two models.
Model A: always predicts “negative”.
It’s right on all 950 negatives and wrong on all 50 positives.
accuracy = (0 + 950) / 1000 = 0.9595% accuracy from a model that has learned nothing and never finds a single positive.
Model B: a more realistic model.
It finds 40 of the 50 positives, misses 10, but also flags 60 negatives by mistake. As a confusion matrix:
| Predicted positive | Predicted negative | |
|---|---|---|
| Actually positive | TP = 40 | FN = 10 |
| Actually negative | FP = 60 | TN = 890 |
accuracy = (40 + 890) / 1000 = 0.93
precision = TP / (TP + FP) = 40 / 100 = 0.40
recall = TP / (TP + FN) = 40 / 50 = 0.80
F1 = 2 * (0.40 * 0.80) / (0.40 + 0.80) = 0.533By accuracy, Model A (0.95) beats Model B (0.93). By recall, A is 0 and B is 0.80. Which one is “better” depends on what you need.
I verified these numbers with a small script that counts TP, FP, FN and TN directly, so you can check them by hand too.
What each metric tells you here:
- Accuracy: the share of all predictions that were right. With 95% negatives, it’s dominated by the majority class.
- Recall: of the real positives, how many did you find? A is 0 and B is 0.80.
- Precision: of the things you flagged, how many were real? B’s is 0.40, so 6 out of 10 alerts are false alarms.
- F1: a single number combining precision and recall. It’s useful for comparison, but it hides the trade-off between the two.
Habits worth building early:
- Always compute a trivial baseline first (like “always predict the majority class”). If your model can’t beat it on the metric you care about, something’s off.
- Look at the confusion matrix, not just one number.
- Choose the metric from the cost of mistakes. Missing a fraud case and a false alarm cost different amounts, and the right trade-off depends on your problem.
- Check how the data is split (train, validation and test should keep a similar class balance).
Limits of this example:
- The numbers are made up to illustrate the idea, not from a real dataset.
- Other tools exist for imbalance (class weights, resampling, threshold tuning, precision-recall curves), and none is “the answer”, so look at what fits your data.
What was the first metric that surprised you when you started with ML?
