Precision vs Recall: What They Mean and When to Optimize Which
Precision and recall measure different failures. Learn what each means, the trade-off between them, and how to decide which to optimize for your problem.
Precision and recall are the two metrics people most often mix up — partly because both are 'how good is my classifier?' numbers, and partly because improving one usually costs the other. The clean way to keep them straight is to remember that each one measures a different kind of mistake. Precision punishes false alarms; recall punishes misses. (Both are computed from the confusion matrix — read that first if TP/FP/FN are new to you.)
The two questions
- Precision = TP / (TP + FP). Of everything the model flagged positive, what fraction actually was? High precision means few false alarms.
- Recall = TP / (TP + FN). Of all the genuinely positive cases, what fraction did the model catch? High recall means few misses.
Why they trade off
Most classifiers output a score, and you choose a threshold above which a case counts as positive. Raise the threshold and the model only flags cases it's very sure about: precision rises, but more real positives slip below the bar, so recall falls. Lower the threshold and the model casts a wider net: recall rises, but more false alarms sneak in, so precision falls. The trade-off isn't a flaw in your model — it's a dial you're expected to set deliberately.
When to optimize which
| Scenario | Costly error | Optimize |
|---|---|---|
| Cancer or disease screening | Missing a sick patient (FN) | Recall — a false alarm leads to a follow-up test; a miss can be fatal |
| Spam filtering | Blocking a real email (FP) | Precision — a spam email in the inbox is annoying; a lost job offer is not |
| Fraud detection (auto-block) | Freezing a legitimate customer (FP) | Precision — with human review downstream, lean toward recall instead |
| Search & retrieval (top results) | Showing irrelevant results (FP) | Precision at the top; recall matters more for exhaustive/legal search |
| Safety recalls, security alerts | Missing a real incident (FN) | Recall — review the extra alarms rather than miss the event |
The one-line decision rule
Ask: which is more expensive here — a false alarm or a miss? Expensive false alarms → optimize precision. Expensive misses → optimize recall. If they cost about the same, use F1 or tune the threshold on a precision–recall curve.
F1 and beyond
The F1 score is the harmonic mean of precision and recall. Unlike a plain average, the harmonic mean collapses toward the weaker of the two — a model with 0.95 precision and 0.10 recall gets an F1 of about 0.18, not 0.52 — so it can't hide a lopsided classifier. When the costs are genuinely asymmetric, the Fβ family lets you weight recall β times as much as precision (F2 favours recall; F0.5 favours precision). And to see the whole trade-off at once rather than a single point, plot the precision–recall and ROC curves across all thresholds — especially informative on imbalanced data.
**AI Learning** covers precision, recall, F1 and threshold tuning across its cheat sheets and roughly 10,000 practice questions with worked explanations — from beginner to interview level, completely offline with no account.
Free · Works offline · Practice metrics questions until the trade-off is second nature.
Sources
Frequently asked questions
More in Learn AI & Data Science
- Coding Interview Strategy: A Framework for Solving Problems Under PressureKnowing algorithms isn't enough — you have to deploy them under pressure. Here's a repeatable framework for solving unseen problems and a study plan that builds durable skill.
- P vs NP and Complexity Classes: What 'Hard' Really Means (Intuition, No Proofs)Why do some problems have fast algorithms and others resist every attempt? P vs NP is the deepest open question in computer science — here's the intuition, minus the proofs.
- Union-Find (Disjoint Set Union): Near-Constant Connectivity with Two OptimizationsUnion-Find answers 'are these two things connected?' and 'connect them' in almost O(1) — thanks to two beautifully simple optimizations that make the trees nearly flat.