Precision and recall answer two genuinely different questions about a classifier's positive predictions โ and understanding the tradeoff between them is essential for choosing the right metric for any specific real-world stakes.
Formulas
| Metric | Question It Answers |
|---|---|
| Precision | "Of everything the model predicted positive, how much was actually positive?" |
| Recall (also called Sensitivity) | "Of everything that was actually positive, how much did the model catch?" |
Numerical Example
Continuing the spam example (TP=24, FP=7, FN=6):
77.4% of emails flagged as spam were actually spam (precision); 80% of all actual spam emails were successfully caught (recall).
The Tradeoff โ Why You Rarely Get Both at Maximum
A classifier's positive/negative decision is typically based on thresholding a predicted probability (e.g. predict "positive" if \(\hat p > 0.5\)). Lowering this threshold flags more examples as positive โ catching more true positives (raising recall) but also more false positives (lowering precision). Raising the threshold does the opposite. This threshold-driven tradeoff is exactly what the ROC and Precision-Recall curves, covered later in this category, visualize directly.
Choosing Which Matters More, by Context
| Scenario | Priority | Why |
|---|---|---|
| Spam detection | Precision | A false positive (legitimate email marked spam) can mean a missed important message โ costly |
| Cancer screening | Recall | A false negative (missed cancer diagnosis) can be life-threatening โ far costlier than a false positive requiring further (harmless) testing |
| Search engine result ranking | Precision | Users care most about the relevance of the few results actually shown to them |
Code
from sklearn.metrics import precision_score, recall_score
y_true = [1,1,1,1,1,0,0,0,0,0]
y_pred = [1,1,1,0,0,0,0,1,0,0]
print(precision_score(y_true, y_pred)) # TP / (TP + FP)
print(recall_score(y_true, y_pred)) # TP / (TP + FN)
Common Mistakes
- Optimizing for precision or recall alone without considering the actual cost asymmetry of the task โ the right balance is always context-dependent, never a universal default.
- Reporting only one of the two metrics โ a model can have excellent precision but terrible recall (or vice versa), and either number alone hides that imbalance; reporting both (or their combination, F1, next) gives a fuller picture.
Interview Relevance
Q: "Why would you prioritize recall over precision for a cancer-screening model, but precision over recall for a spam filter?" For cancer screening, a false negative (missing an actual cancer case) can be far more costly than a false positive (an unnecessary follow-up test) โ prioritizing recall minimizes missed diagnoses. For spam filtering, a false positive (a legitimate email incorrectly marked spam) can mean missing something important, while a missed spam email (false negative) is a comparatively minor inconvenience โ prioritizing precision minimizes that more costly error type.
Practice Question
Using the medical diagnosis confusion matrix from earlier (TP=45, FN=5, FP=15, TN=135), compute both precision and recall.