Precision vs Recall: What's the Difference?
Learn the difference between precision and recall, their formulas, the tradeoff between them, and when to prioritize each in classification models.
Expected Interview Answer
Precision measures how many of the items a model flagged as positive are actually positive (true positives divided by all predicted positives), while recall measures how many of the actual positive items the model successfully found (true positives divided by all actual positives).
Precision answers 'when the model says yes, how often is it right?' and is calculated as TP / (TP + FP), penalizing false positives. Recall answers 'of all the actual positives, how many did the model catch?' and is calculated as TP / (TP + FN), penalizing false negatives. The two typically trade off against each other as you move a classification threshold: raising the threshold to be more selective increases precision but lowers recall, and vice versa. Which one to prioritize depends on the cost of each error type — spam filtering favors precision (avoid flagging legitimate email), while disease screening favors recall (avoid missing a sick patient). The F1 score, the harmonic mean of precision and recall, gives a single balanced metric when both matter.
- Precision protects against costly false positives
- Recall protects against costly missed detections (false negatives)
- Choosing the right metric aligns model behavior with real business/safety cost
- The precision-recall tradeoff guides threshold tuning
- F1 score gives a single balanced number when both matter equally
AI Mentor Explanation
Precision is like an umpire's LBW-out calls: of everyone given out, what fraction actually were out, measuring how trustworthy each dismissal call is. Recall is a different question: of every batsman who was truly out, what fraction did the umpire correctly identify, measuring how many real dismissals got missed entirely and let a batsman survive.
Step-by-Step Explanation
Step 1
Build the confusion matrix
Get true positives, false positives, and false negatives from your model's predictions on labeled data.
Step 2
Compute precision
Divide true positives by the sum of true positives and false positives: TP / (TP + FP).
Step 3
Compute recall
Divide true positives by the sum of true positives and false negatives: TP / (TP + FN).
Step 4
Identify the cost asymmetry
Determine whether false positives or false negatives are more costly for your specific application.
Step 5
Tune the decision threshold
Raise the threshold to favor precision, or lower it to favor recall, based on that cost tradeoff.
Step 6
Combine with F1 if both matter
Use the F1 score (harmonic mean of precision and recall) when you need one balanced metric instead of optimizing either alone.
What Interviewer Expects
- Gives the correct formulas for precision and recall
- Explains the precision-recall tradeoff via threshold movement
- Can give a real example where precision matters more (spam) and one where recall matters more (disease screening)
- Mentions F1 score as the balancing metric
- Connects the concept back to the confusion matrix
Common Mistakes
- Swapping the formulas for precision and recall
- Assuming one metric is always more important than the other
- Ignoring the tradeoff and trying to maximize both without acknowledging the cost
- Confusing recall with accuracy
- Forgetting that threshold choice directly controls this tradeoff
Best Answer (HR Friendly)
“Precision tells you how often the model is right when it says something is positive, while recall tells you how many of the actual positive cases the model successfully caught. There's often a tradeoff: being more cautious improves precision but can miss more real cases, lowering recall, so the right balance depends on what mistake is more costly.”
Code Example
from sklearn.metrics import precision_score, recall_score, f1_score
y_true = [1, 0, 1, 1, 0, 1, 0, 0]
y_pred = [1, 0, 0, 1, 0, 1, 1, 0]
print("Precision:", precision_score(y_true, y_pred)) # TP / (TP + FP)
print("Recall:", recall_score(y_true, y_pred)) # TP / (TP + FN)
print("F1:", f1_score(y_true, y_pred)) # harmonic meanFollow-up Questions
- How does adjusting the classification threshold affect precision and recall?
- What is the F1 score and why is it the harmonic mean rather than the average?
- Give an example where you would optimize for recall over precision.
- What is a precision-recall curve and when is it preferred over an ROC curve?
- How would you handle a use case where both false positives and false negatives are very costly?
MCQ Practice
1. What does precision measure?
Precision is TP / (TP + FP): among everything the model flagged as positive, the fraction that was truly positive.
2. For a disease screening test where missing a sick patient is very costly, you should prioritize:
High recall minimizes false negatives, which is critical when missing an actual positive case (a sick patient) has severe consequences.
3. What does the F1 score represent?
F1 score is the harmonic mean of precision and recall, which penalizes extreme imbalance between the two more than a simple average would.
Flash Cards
What is the formula for precision? — TP / (TP + FP) — of all predicted positives, the fraction that are truly positive.
What is the formula for recall? — TP / (TP + FN) — of all actual positives, the fraction correctly identified.
When would you prioritize precision over recall? — When false positives are costly, e.g. spam filtering, where flagging legitimate email is worse than missing some spam.
What metric balances precision and recall into one number? — The F1 score, the harmonic mean of precision and recall.