How do precision and recall differ?
Precision and recall measure different aspects of positive-class performance. Precision asks how reliable the model's positive predictions are; recall asks how many real positive cases it successfully finds.
The key difference
- Precision: “Of everything predicted positive, how much is truly positive?” It is affected by false positives.
- Recall: “Of everything actually positive, how much did we detect?” It is affected by false negatives.
Their formulas are:
Precision = TP / (TP + FP)
Recall = TP / (TP + FN)The numerators are the same (true positives), but the denominators are different: precision considers all *predicted positives*, whereas recall considers all *actual positives*.
Worked example: fraud detection
Imagine a fraud-screening model evaluating 100 transactions:
- TP = 30: genuine fraud correctly flagged.
- FP = 10: legitimate transactions incorrectly flagged.
- FN = 20: genuine fraud the model missed.
- TN = 40: legitimate transactions correctly cleared.
Precision = 30 / (30 + 10)
= 30 / 40 = 0.75 = 75%
Recall = 30 / (30 + 20)
= 30 / 50 = 0.60 = 60%Interpretation: When the system raises an alert, 75% of alerts are genuine fraud; of all real fraud cases, it catches 60%. These are *not* two ways of describing the same result.
When should you favor each metric?
- Favor precision when false alarms cost more. For example, if each fraud alert temporarily freezes a customer's account, you want flagged transactions to be trustworthy.
- Favor recall when missed cases cost more. For example, for early detection of dangerous equipment failures, finding as many genuine failures as possible may justify additional false alarms.
A model may have high recall but low precision when it labels many examples positive. Another model may have high precision but low recall when it issues very few carefully selected alerts. Neither extreme is automatically best.
Python example
PYTHONfrom sklearn.metrics import precision_score, recall_score # TP=30, FP=10, FN=20, TN=40 y_true = [1]*30 + [0]*10 + [1]*20 + [0]*40 y_pred = [1]*30 + [1]*10 + [0]*20 + [0]*40 print("Precision:", precision_score(y_true, y_pred)) # 0.75 print("Recall:", recall_score(y_true, y_pred)) # 0.60
Common points of confusion
- Precision is not accuracy: accuracy counts correctly classified negatives too; precision focuses on predictions labeled positive.
- Recall is also called sensitivity or true positive rate. It is not specificity; specificity measures correctly recognized actual negatives.
- Metrics depend on the decision threshold: moving the threshold changes which examples count as positive. Precision and recall often trade off, but the change is data-dependent; their trade-off is explored in the next question.
- Define the positive class and the evaluation dataset before comparing scores. For multiclass problems, calculate per-class metrics or specify an averaging method.
In short: precision measures false-alarm control among positive predictions; recall measures missed-case control among actual positives. Choose based on which mistakes your application can tolerate.
References
Learning Sequence
Machine Learning Curriculum
Explore Related Questions
Deepen your understanding across related Machine Learning topics.