MACHINE LEARNING · QUESTION 17
What are precision, recall, and F1, and when should you use each?
On this page
Precision asks what fraction of predicted positives are truly positive; recall asks what fraction of actual positives the model finds. F1 is their harmonic mean and balances the two, but it does not reflect true negatives or application-specific costs. I choose a metric based on the consequences of false positives and false negatives, then select a decision threshold using validation data.
LET'S MAKE IT SIMPLE
First, the idea in plain English
A classifier often decides whether something belongs to a category, such as whether a transaction is fraudulent. There are two common ways it can be wrong: flag a legitimate transaction or miss a fraudulent one. Precision focuses on how trustworthy positive alerts are; recall focuses on how many real positives were caught. F1 combines those two numbers, but no metric is automatically right for every product.
A USEFUL COMPARISON
Picture it this way
Think of a smoke alarm. Precision asks, “When it rings, how often is there really a fire?” Recall asks, “Of all fires, how many did the alarm catch?” A system that never rings has no false alarms but misses every fire. The analogy highlights different error costs; a real classifier also needs calibration, thresholds, and representative data.
FOLLOW THE JOURNEY
A confusion matrix separates the two error types
Connect true/false positives and negatives to precision, recall, and F1.
Precision and recall are undefined when their denominators are zero; evaluation libraries expose conventions for these cases. Always state the positive class.
A binary confusion matrix labels true positives, false positives, false negatives, and true negatives, with precision using predicted positives and recall using actual positives.
How to read this visual
Precision and recall are undefined when their denominators are zero; evaluation libraries expose conventions for these cases. Always state the positive class.
UNDER THE HOOD
How it works, step by step
Define the positive class
Specify which outcome counts as positive and what each error costs.
Why it matters: The metric interpretation changes if the class is reversed.
Count outcomes
Compare predictions with verified labels to get true and false positives and negatives.
Why it matters: The confusion matrix makes error types visible.
Calculate useful metrics
Compute precision, recall, and optionally F1 for the chosen operating point.
Why it matters: Each number emphasizes a different part of classifier behavior.
Choose a threshold
Use validation data and business constraints to select when a score becomes a positive prediction.
Why it matters: A threshold changes precision-recall trade-offs without changing the model itself.
OUTSIDE THE TEXTBOOK
A practical example
For a medical screening test, missing a disease may be more costly than sending some healthy people for additional testing, so recall may be prioritized. A follow-up diagnostic step can then improve precision. The acceptable threshold should be set with domain experts and evaluated on representative data, not chosen only because it maximizes F1.
GO A LITTLE DEEPER
Technical details that matter
- Precision = TP / (TP + FP); recall = TP / (TP + FN); F1 = 2 × precision × recall / (precision + recall).
- Changing a classification threshold usually trades precision against recall; a precision-recall curve shows behavior across thresholds.
- Macro averaging gives classes equal weight, while micro averaging aggregates decisions; weighted averages account for class support.
- For calibrated probabilities and known costs, expected cost or utility may be more actionable than a single threshold-free metric.
MAKE A GOOD CHOICE
When is this useful?
- Prioritizing rare positive cases such as fraud alerts or safety events.
- Comparing classifiers when false positives and false negatives have different consequences.
- Communicating model behavior beyond raw accuracy on imbalanced data.
Use ROC-AUC to assess ranking across thresholds in some settings, PR-AUC when positive cases are rare, calibration metrics for probability quality, or explicit expected cost when outcome costs are known.
WATCH OUT FOR
Common misunderstandings
- Reporting F1 without explaining the positive class or error costs.
- Using accuracy alone when classes are highly imbalanced.
- Comparing metrics from different validation populations or thresholds as if they were directly equivalent.
REAL-WORLD TRADE-OFFS
Limitations and failure cases
- Precision and recall depend on class prevalence and can change when deployment populations shift.
- F1 ignores true negatives and assumes a particular balance between precision and recall.
- Labels may be delayed or imperfect, making measured performance misleading.
WHAT TO REMEMBER
Key takeaways
- 1Precision measures the reliability of positive predictions.
- 2Recall measures how many actual positives are found.
- 3F1 balances precision and recall but does not encode every error cost.
- 4Choose thresholds and metrics based on the actual decision and representative validation data.
PRACTICE THE FOLLOW-UP
What might an interviewer ask next?
Why can accuracy be misleading?
When one class dominates, predicting that class every time can achieve high accuracy while failing to identify the rare class that matters.
How does the threshold affect precision and recall?
Raising the positive threshold often reduces false positives and raises precision, but can miss more positives and lower recall. The exact curve depends on the model and data.
When is PR-AUC more useful than ROC-AUC?
Precision-recall views can be more informative when positives are rare and the quality of positive predictions matters. The choice still depends on the operational decision.
SAY IT OUT LOUD
How to explain this in an interview
“Precision tells me how many positive predictions are correct; recall tells me how many actual positives the model finds. F1 combines them, but it ignores true negatives and does not encode product costs. For a screening task, I might prioritize recall if missing a positive is especially harmful. I would define the positive class, evaluate on representative data, and choose a threshold based on the real decision.”
Connect this question to the roadmap topic it supports.