Precision vs Recall
Precision answers "of everything the model flagged positive, how much was actually positive?" Recall answers "of everything that was actually positive, how much did the model catch?" You tune toward one or the other depending on whether false positives or false negatives hurt more.
How Do Precision and Recall Come From the Confusion Matrix?
Both metrics are ratios built from the four cells of a confusion matrix: true positives (TP), false positives (FP), false negatives (FN), and true negatives (TN).
Precision = TP / (TP + FP) # of my positive predictions, how many were right?
Recall = TP / (TP + FN) # of the real positives, how many did I find?
# Example: 100 real fraud cases, model flags 60 transactions, 45 are real fraud
# Precision = 45 / 60 = 0.75
# Recall = 45 / 100 = 0.45
When Does Precision Matter More?
Optimize precision when a false positive is expensive or erodes trust, like a spam filter โ flagging a real email as spam (FP) means someone misses a job offer, while letting one spam email through (FN) is a minor annoyance.
When Does Recall Matter More?
Optimize recall when a false negative is catastrophic, like cancer screening โ missing a real case (FN) can be fatal, while a false alarm (FP) just triggers a follow-up test. Fraud detection and safety alerts usually lean this way too.
What Is the F1 Score?
F1 is the harmonic mean of precision and recall, giving a single number that is only high when both are high.
F1 = 2 * (precision * recall) / (precision + recall)
# precision=0.75, recall=0.45 -> F1 = 0.5625
# The harmonic mean punishes imbalance: 0.9 and 0.1 gives F1 = 0.18, not 0.5
Why Is There a Precision-Recall Tradeoff?
Most classifiers output a probability, and you pick a threshold: raising it makes the model pickier (precision up, recall down), lowering it makes it greedier (recall up, precision down). Plot precision and recall across thresholds and pick the point that matches your cost of errors instead of accepting the default 0.5.
Common Pitfalls
- Trusting accuracy on imbalanced data: with 1% fraud, predicting "never fraud" is 99% accurate with zero recall. Always report precision and recall separately.
- Reporting F1 alone: F1 weights both errors equally. If your FP and FN costs differ, say so and pick the metric that matches.
- Comparing models at different thresholds: use the full precision-recall curve (or average precision) for a fair comparison.
- Forgetting recall has an alias: recall is also called sensitivity or true positive rate in medical and ROC contexts. Same formula.
Pro Tip: Never accept a classifier's default 0.5 threshold. Sweep thresholds on a validation set, plot precision and recall, and hand stakeholders the tradeoff curve โ the business, not the model, should choose where to sit on it.
โ Back to AI & ML Tips