Precision vs Recall, Explained
Precision measures how many of a model's positive predictions were correct; recall measures how many actual positives it found. Why you can't max both.
Precision answers “of everything the model flagged as positive, how much actually was?” Recall answers “of everything that was actually positive, how much did the model find?” Both are ways of scoring a classifier that goes beyond plain accuracy, and they matter because a model can score well on one while doing badly on the other — a spam filter that marks nothing as spam has perfect precision on the spam it does catch (there is none to be wrong about) and zero recall, since it misses every actual spam message.
Why accuracy alone isn’t enough
Accuracy — the fraction of all predictions that were correct — falls apart on imbalanced data. Imagine a fraud-detection model evaluated on transactions where only 1 in 1,000 is actually fraudulent. A model that simply predicts “not fraud” every single time is 99.9% accurate, and completely useless — it catches nothing. Precision and recall exist because they force you to look specifically at how the model handles the positive class, which is usually the class you actually care about.
The confusion matrix underneath both metrics
Every prediction a binary classifier makes falls into one of four buckets:
- True positive (TP) — predicted positive, actually positive.
- False positive (FP) — predicted positive, actually negative. A false alarm.
- False negative (FN) — predicted negative, actually positive. A miss.
- True negative (TN) — predicted negative, actually negative.
Precision and recall are both computed from these counts, but they divide by different totals:
Precision = TP / (TP + FP) — of what was flagged positive, how much was correct
Recall = TP / (TP + FN) — of what was actually positive, how much was flagged
Precision’s denominator is everything the model called positive. Recall’s denominator is everything that was positive, regardless of what the model said. That’s the whole distinction, and it’s why the two numbers can move in opposite directions from the same model.
A worked example
Say a spam filter processes 1,000 emails, 50 of which are actually spam. The filter flags 60 emails as spam; of those 60, 40 really are spam (true positives), and 20 are legitimate emails wrongly flagged (false positives). It misses 10 of the real spam emails (false negatives), letting them through as “not spam.”
- Precision = 40 / (40 + 20) = 40 / 60 ≈ 67%. Of everything flagged spam, two-thirds actually was.
- Recall = 40 / (40 + 10) = 40 / 50 = 80%. Of all the real spam that existed, the filter caught 80% of it.
Both numbers describe the same model from different angles, and neither alone tells the full story — a model could hit either one in isolation trivially, which is exactly why they’re reported together.
Why you can’t maximize both at once
Most classifiers don’t output a hard yes/no — they output a score or probability, and a threshold decides where “positive” starts. Moving that threshold trades precision against recall directly.
Lower the threshold so the model flags more things as positive, and recall goes up — you catch more of the real positives, because you’re casting a wider net — but precision tends to fall, because that wider net also catches more false positives. Raise the threshold to be more selective, and precision improves — you’re only flagging things the model is very confident about — but recall falls, because some real positives no longer clear the higher bar. This is the precision-recall trade-off, and it’s a property of the threshold, not a flaw in the model.
Deciding where to set that threshold is a judgment call about which error is more expensive in your specific application, not something a single metric can answer for you.
Which one matters more depends on the cost of being wrong
- Medical screening typically favors recall. Missing a real case (a false negative) can mean a serious illness goes undetected, while a false positive just leads to a follow-up test that rules it out. Screening tools are deliberately tuned to catch nearly everything, accepting more false alarms in exchange.
- Spam filtering typically favors precision. A false positive — a legitimate email marked spam and never seen — can mean a missed job offer or an important bill. Letting a few extra spam messages through (a false negative) is the cheaper mistake by comparison.
- Search and recommendation ranking often cares about both, and blends them into a single number — commonly the F1 score, the harmonic mean of precision and recall — so a system can’t game one metric by ignoring the other.
Where this shows up beyond classic ML
The same trade-off applies directly to evaluating retrieval systems, including the retrieval step in RAG pipelines: a retriever with high recall returns most of the relevant documents but also pulls in noise, while one tuned for high precision returns fewer, cleaner results at the risk of missing something relevant. It also underlies how LLM evals score classification-style tasks, and it’s a direct consequence of the same overfitting-vs-underfitting tension — a model tuned too aggressively toward one metric on training data often loses ground on the other when it meets real, unseen inputs.
The takeaway
Precision tells you how trustworthy a positive prediction is; recall tells you how completely the model finds the positives that exist. They trade off against each other as you move a classification threshold, and there’s no universal “right” balance — a medical screening tool and a spam filter reasonably land in opposite places on that trade-off, because the cost of a false positive and a false negative aren’t the same in either case. Report both, or a blended metric like F1, rather than either one alone.
Tagged
Keep reading
Chisato · · 5 min read Grouped-Query Attention (GQA) Explained: MHA vs MQA vs GQA
Grouped-query attention shares key and value heads across groups of query heads, shrinking the KV cache with little quality loss. GQA vs MHA and MQA.
Chisato · · 5 min read Constrained Decoding: How LLMs Output Guaranteed JSON
Constrained decoding masks invalid tokens at each step so an LLM can only emit output matching a grammar, regex, or JSON Schema. How it works and its limits.
Chisato · · 5 min read LLM Logprobs Explained: Token Probabilities in Practice
Logprobs are the log probabilities an LLM assigns to each token it generates. What they mean, how to read them, and practical uses like classification.