Precision vs Recall
A practical guide to precision and recall in machine learning, including their formulas, confusion matrix, trade-offs, examples, and real-world use cases.
Precision and recall are two of the most important metrics for evaluating classification models. Both describe how well a model identifies positive cases, but they answer different questions. Precision focuses on the quality of positive predictions, while recall focuses on how many of the actual positive cases the model successfully finds.
Understanding the difference between precision and recall is especially important when a dataset is imbalanced or when false positives and false negatives have different consequences. A spam filter, fraud detector, medical screening system, and search engine may all use classification, but each can have a different reason to prioritize precision or recall.
What Is Precision?
Precision measures how many of the cases predicted as positive are actually positive. In other words, it answers the question: when the model says something is positive, how often is it correct?
A model with high precision produces relatively few false positive predictions. This makes precision particularly important when incorrectly labeling a negative case as positive is expensive, inconvenient, or potentially harmful.
For example, consider an email spam classifier. If the model marks 100 emails as spam and 95 of them are actually spam, its precision is 95%. The remaining five messages are false positives.
Precision is therefore concerned with the reliability of positive predictions.
What Is Recall?
Recall measures how many of the actual positive cases the model successfully identifies. It answers the question: of all the cases that are actually positive, how many did the model find?
A model with high recall produces relatively few false negatives. This makes recall important when failing to identify a real positive case is particularly costly.
For example, suppose a fraud detection system contains 100 fraudulent transactions and successfully identifies 90 of them. Its recall is 90%, assuming the evaluation set contains those 100 actual positive cases.
Recall is therefore concerned with coverage of the positive class.
Precision vs Recall at a Glance
| Metric | Main question | Focus | Penalizes |
|---|---|---|---|
| Precision | When the model predicts positive, how often is it correct? | Quality of positive predictions | False positives |
| Recall | How many actual positives did the model find? | Coverage of positive cases | False negatives |
The simplest way to remember the distinction is that precision asks whether positive predictions are trustworthy, while recall asks whether the model is finding most of the positives that exist.
Precision and Recall from the Confusion Matrix
Both metrics are calculated from values in a confusion matrix. For a binary classifier, predictions can be divided into true positives, true negatives, false positives, and false negatives.
| Actual / Predicted | Positive | Negative |
|---|---|---|
| Positive | True Positive | False Negative |
| Negative | False Positive | True Negative |
A true positive occurs when the model predicts positive and the actual class is positive. A false positive occurs when the model predicts positive but the actual class is negative. A false negative occurs when the model predicts negative even though the actual class is positive.
Precision uses true positives and false positives. Recall uses true positives and false negatives. True negatives do not directly appear in either metric's calculation.
How Precision and Recall Are Calculated
Precision is calculated as the number of true positives divided by all positive predictions. Recall is calculated as the number of true positives divided by all actual positive cases.
This difference in denominators explains why the metrics measure different properties. Precision looks at what the model predicted as positive, while recall looks at what was actually positive.
A Simple Example
Imagine a model designed to detect fraudulent transactions. There are 1,000 transactions in the evaluation dataset, including 100 fraudulent transactions. The model identifies 80 of those fraudulent transactions, but it also incorrectly flags 20 legitimate transactions as fraudulent.
| Outcome | Count |
|---|---|
| True positives | 80 |
| False positives | 20 |
| False negatives | 20 |
| True negatives | 880 |
The model predicted 100 transactions as fraudulent, and 80 of them really were fraudulent. Therefore, its precision is 80%.
There were 100 fraudulent transactions in total, and the model detected 80 of them. Therefore, its recall is also 80% in this example.
The equal values are coincidental. Precision and recall can differ significantly depending on how the model behaves.
A Model with High Precision and Low Recall
Suppose a fraud detection model is extremely conservative. It flags only transactions that look almost certainly fraudulent. As a result, nearly every transaction it flags is actually fraudulent.
This produces high precision because there are few false positives. However, the model may miss many fraudulent transactions, resulting in low recall.
Such a model can be useful when investigating a false alarm is expensive, but it may be unsuitable when the primary goal is to detect as much fraud as possible.
A Model with Low Precision and High Recall
Now consider a model that flags almost anything that might be fraudulent. It catches nearly all fraudulent transactions, producing high recall, but it also flags many legitimate transactions.
Because many positive predictions are incorrect, precision becomes lower.
This approach may be appropriate when missing a positive case is much worse than generating additional false alarms.
The Precision-Recall Trade-Off
In many classification problems, increasing recall comes at the cost of precision, and increasing precision comes at the cost of recall. This happens because the model often produces a continuous score or probability that must be converted into a positive or negative prediction using a threshold.
If the threshold is lowered, the model becomes more willing to classify cases as positive. This usually increases recall because more actual positive cases are captured. However, it can also increase the number of false positives and reduce precision.
If the threshold is raised, the model becomes more conservative. This can reduce false positives and increase precision, but it may also cause the model to miss more actual positives, reducing recall.
| Threshold strategy | Typical effect on precision | Typical effect on recall |
|---|---|---|
| Lower threshold | Decrease | Increase |
| Higher threshold | Increase | Decrease |
Why the Classification Threshold Matters
Many machine learning classifiers do not directly produce a final class. Instead, they produce a probability or score. A separate threshold determines whether that score becomes a positive prediction.
For example, a binary classifier might predict that an observation has a 0.72 probability of belonging to the positive class. If the threshold is 0.5, it is classified as positive. If the threshold is 0.8, it is classified as negative.
The threshold should not automatically be assumed to be 0.5. It should be selected according to the application's requirements and the relative costs of false positives and false negatives.
When Should You Prioritize Precision?
Precision should be prioritized when false positives are especially costly. In these situations, the application benefits from making positive predictions only when there is strong evidence that they are correct.
- Spam filtering where legitimate messages should not be incorrectly blocked
- Content moderation where incorrectly removing legitimate content is costly
- Search or recommendation systems where displayed results should be highly relevant
- Fraud investigation systems where every alert requires expensive manual review
- Automated actions that could negatively affect a legitimate user
A high-precision system may intentionally miss some positive cases if doing so keeps false alarms under control.
When Should You Prioritize Recall?
Recall should be prioritized when false negatives are especially costly. The objective is to identify as many actual positive cases as possible, even if some additional false positives are produced.
- Security threat detection
- Fraud screening when missed fraud is highly costly
- Medical screening where missing a potentially serious condition is dangerous
- Defect detection in manufacturing
- Finding relevant documents in information retrieval
- Identifying potentially harmful events that require further investigation
A high-recall system accepts that additional false positives may need to be reviewed in order to reduce the number of missed positive cases.
Precision vs Recall for Imbalanced Data
Precision and recall are especially useful when the positive class is rare. This situation is known as class imbalance.
Consider a fraud dataset containing 99,000 legitimate transactions and only 1,000 fraudulent transactions. A model that predicts every transaction as legitimate would achieve 99% accuracy, but its recall for fraud would be 0%. It would detect none of the fraudulent transactions.
Precision and recall expose this problem much more clearly because they focus directly on the positive class and its errors.
For highly imbalanced classification, it is therefore common to report precision and recall alongside metrics such as F1 and precision-recall AUC rather than relying on accuracy alone.
Precision-Recall Curve
A precision-recall curve shows how precision changes as recall changes across different classification thresholds. Each threshold produces a different pair of precision and recall values.
The curve helps developers understand the trade-off instead of evaluating the model at only one arbitrary threshold. It can be especially informative for imbalanced classification problems where the positive class is rare.
A model that maintains relatively high precision while achieving high recall is generally more useful than one that reaches high recall only by generating a very large number of false positives.
Precision vs Recall vs Accuracy
Accuracy measures the proportion of all predictions that are correct. Precision and recall focus specifically on the positive class and its associated errors.
| Metric | Focus | Useful when |
|---|---|---|
| Accuracy | Overall proportion of correct predictions | Classes are reasonably balanced and errors have similar costs |
| Precision | Correctness of positive predictions | False positives are costly |
| Recall | Coverage of actual positive cases | False negatives are costly |
Accuracy can be useful, but it should not automatically be preferred simply because it is easy to understand. The metric must match the problem being solved.
Precision vs Recall vs F1 Score
Precision and recall are often combined using the F1 score. F1 provides a single metric that balances the two values and is based on their harmonic mean.
F1 can be useful when both precision and recall matter and neither should be ignored. However, it can hide the individual trade-off between the two metrics. A model should therefore not be evaluated using F1 alone when the application has a clear preference for either precision or recall.
For example, a medical screening system may care much more about recall than precision. In that situation, inspecting recall directly is more informative than relying only on F1.
How to Choose Between Precision and Recall
The decision should begin with the consequences of false positives and false negatives. Ask which type of mistake is more expensive, dangerous, or disruptive.
| Question | Metric to prioritize |
|---|---|
| Are false positive predictions especially costly? | Precision |
| Are false negative predictions especially costly? | Recall |
| Are both types of errors important? | Precision and recall together, potentially F1 |
| Is the positive class very rare? | Precision, recall, and PR-AUC |
| Does the probability itself drive decisions? | Consider probability calibration and log loss |
Use Cases in Practice
The appropriate balance between precision and recall depends heavily on the application.
| Application | Likely priority | Reason |
|---|---|---|
| Spam filtering | Precision | Avoid incorrectly sending legitimate emails to spam |
| Security detection | Recall | Missing a real threat can be costly |
| Medical screening | Recall | Missing a possible condition can be more serious |
| Search results | Precision | Top results should be highly relevant |
| Fraud detection | Depends on the workflow | The cost of missed fraud and investigation workload must be balanced |
| Defect detection | Often recall | Missing a defective product can be costly |
Precision and Recall in Multiclass Classification
Precision and recall can also be calculated for multiclass classification. Instead of treating the entire problem as one positive-versus-negative decision, each class can be evaluated separately.
For example, a model classifying images into cats, dogs, and birds can have high precision for cats but lower recall for birds. Reporting only one aggregate value could hide these differences.
Macro, micro, and weighted averaging can then be used to combine per-class results into summary metrics. Macro averaging gives each class equal importance, while weighted averaging accounts for the number of examples in each class.
Can You Maximize Both Precision and Recall?
In general, improving a model can sometimes increase both precision and recall, especially when the underlying model becomes better at separating the classes. However, for a fixed model, changing the classification threshold often creates a trade-off between them.
The goal is therefore not always to maximize one metric independently. Instead, the objective is to find a useful operating point that reflects the application's requirements.
A better model can shift the precision-recall curve upward, making it possible to achieve better recall at the same precision or better precision at the same recall.
Common Mistakes
- Choosing precision or recall without considering the cost of errors.
- Using accuracy alone for highly imbalanced datasets.
- Assuming that a 0.5 classification threshold is always optimal.
- Looking only at one precision or recall value without examining different thresholds.
- Optimizing recall while ignoring the operational cost of false positives.
- Optimizing precision while allowing too many real positive cases to be missed.
- Using F1 as the only metric when the application clearly prioritizes one type of error.
- Reporting aggregate metrics without checking performance for individual classes.
- Evaluating metrics only on training data.
Best Practices
- Define the positive class explicitly.
- Understand the consequences of false positives and false negatives.
- Use a representative validation and test dataset.
- Inspect the confusion matrix alongside precision and recall.
- Evaluate multiple classification thresholds when appropriate.
- Use precision-recall curves for threshold analysis.
- Report both precision and recall when both error types matter.
- Use F1 when a balanced summary is useful.
- Pay special attention to precision and recall for rare positive classes.
- Evaluate individual classes in multiclass problems.
- Choose the operating threshold using validation data rather than the test set.
- Monitor the chosen metrics after deployment because data distributions can change.
Frequently Asked Questions
What is the main difference between precision and recall?
Precision measures how many positive predictions are actually correct, while recall measures how many of the actual positive cases the model successfully identifies. Precision focuses on false positives, while recall focuses on false negatives.
Which is better, precision or recall?
Neither is universally better. Precision is more important when false positives are costly, while recall is more important when false negatives are costly. The correct choice depends on the application.
Why does increasing recall often reduce precision?
Lowering the classification threshold usually causes the model to predict more cases as positive. This can capture more actual positives and increase recall, but it can also create more false positives, which reduces precision.
Is high accuracy better than high precision or recall?
Not necessarily. Accuracy can be misleading when classes are imbalanced. A model can have very high accuracy while failing to detect most examples of a rare positive class. Precision and recall can provide a more useful view in such cases.
Should I use F1 instead of precision and recall?
F1 is useful when both precision and recall are important and a single summary metric is needed. However, you should still inspect precision and recall separately when the application has different costs for false positives and false negatives.
Conclusion
Precision and recall measure two different aspects of classification performance. Precision tells you how reliable positive predictions are, while recall tells you how effectively the model finds the positive cases that actually exist.
The right balance depends on the consequences of prediction errors. When false positives are costly, precision usually deserves more attention. When false negatives are costly, recall becomes more important. For problems where both matter, precision, recall, and F1 can be considered together.
The most important principle is to choose the metric and classification threshold based on the real objective of the system. Evaluating precision and recall on representative unseen data, examining the confusion matrix, and testing different thresholds provides a much more reliable picture of model performance than relying on accuracy alone.