Blog · Machine learning

Accuracy is lying to you: baselines, imbalance, precision and recall

Why a model that's right 89% of the time can be almost useless, and the three questions to ask before you trust any accuracy score.

Here's a real example. A one-line rule, "a message is spam if it contains the word free", is right on 88.98% of 5,574 text messages from a public spam dataset.

That sounds good. It isn't.

Question 1: what does doing nothing score?

Answer "not spam" for every single message, without reading any of them, and you're right 86.60% of the time, because most messages aren't spam.

So the rule beats doing nothing by just 2.38 percentage points. Almost all of its "accuracy" comes from the fact that the easy answer is usually right.

Always compare a score with the simplest baseline: predict the most common class, predict the average, predict yesterday's value. A score on its own tells you almost nothing.

Question 2: is one class much rarer than the other?

When one class is rare, accuracy is dominated by the common one. A fraud model that says "legitimate" for every transaction can be over 99% accurate and catch zero fraud.

That's why accuracy is the wrong headline number for imbalanced problems: fraud, disease screening, churn, defects, spam.

Question 3: which mistake costs more?

There are two ways to be wrong:

  • a false positive: flagging something that's fine (a real email sent to spam),
  • a false negative: missing something that matters (a fraud you didn't catch).

Two numbers describe them:

  • Recall: of all the real positives, how many did you find? TP / (TP + FN)
  • Precision: of everything you flagged, how much was really positive? TP / (TP + FP)

Optimise recall when a miss is expensive: cancer screening, fraud you must catch. Optimise precision when a false alarm is expensive: a spam filter that must not lose real mail, a list of customers you'll pay to call.

And always read one beside the other. A model that flags everything has 100% recall and is useless.

The confusion matrix: where all of this comes from

Count your predictions in a 2×2 table: actual class in the rows, predicted class in the columns. True negatives, false positives, false negatives, true positives. Every metric above is a ratio of these four counts.

A common mistake: textbooks and libraries don't all agree on which axis is which. Label both axes every time, or you'll swap your false positives and false negatives without noticing.

Thresholds: the decision you're actually making

Most classifiers output a score or probability, and you pick the threshold that turns it into a yes or no. Moving the threshold trades precision for recall. An ROC curve shows that trade-off across every threshold; the AUC summarises how well the model ranks positives above negatives.

The right threshold isn't 0.5 by default. It's the one that minimises what your mistakes actually cost.

The checklist

Before you trust an accuracy score, ask:

  1. What does the simplest baseline score on the same data?
  2. How rare is the class I care about?
  3. Which mistake costs more, and what are precision and recall at my threshold?

If you can answer those three, you're already evaluating models better than most tutorials teach.


Model evaluation is Stage 5 of SchoolWhool's Foundations of AI course, the stage we call the most important.

First Principles, the SchoolWhool newsletter

One machine learning idea, explained properly, every week.

The intuition, the common mistake, and a five-minute way to try it yourself. Written by Gaurav.