Precision-Recall Tradeoffs Explained With a Practical Example

Precision-Recall Tradeoffs Explained With a Practical Example

When building a classification model, accuracy can be useful, but it does not always tell you whether the model is making the right decisions.

Imagine a fraud detection system that correctly classifies 98% of transactions. That sounds impressive until you discover that it misses a large percentage of actual fraudulent transactions.

This is where precision and recall become important.

Precision and recall measure different aspects of classification performance. Improving one can sometimes reduce the other, creating what is known as the precision-recall tradeoff.

In this guide, you’ll learn what precision and recall mean, how they are calculated, why they can conflict with each other, and how to understand the tradeoff using a practical example.

What Is Precision?

Precision measures how many of the observations predicted as positive are actually positive.

The formula is:

Precision = True Positives / (True Positives + False Positives)

In other words:

When the model says “positive,” how often is it correct?

For example, suppose a fraud detection model flags 100 transactions as fraudulent.

Out of those 100 transactions:

  • 80 are actually fraudulent
  • 20 are legitimate

The precision is:

Precision = 80 / (80 + 20)
         = 80 / 100
         = 0.80

So the model has 80% precision.

A high precision score means the model produces relatively few false positive predictions.

What Is Recall?

Recall measures how many of the actual positive observations the model successfully identifies.

The formula is:

Recall = True Positives / (True Positives + False Negatives)

Another way to think about recall is:

Of all the actual positive cases, how many did the model find?

Suppose there are 100 fraudulent transactions in a dataset and the model identifies 80 of them.

If it misses 20, then:

Recall = 80 / (80 + 20)
       = 80 / 100
       = 0.80

The model therefore has 80% recall.

A high recall score means the model is good at finding actual positive cases.

Precision vs Recall

The easiest way to distinguish the two metrics is to focus on what each one asks.

MetricMain Question
PrecisionWhen the model predicts positive, how often is it correct?
RecallOf all actual positives, how many did the model find?

Precision is concerned with the quality of positive predictions.

Recall is concerned with the coverage of actual positive cases.

This difference becomes especially important when false positives and false negatives have different costs.

Understanding the Confusion Matrix

Precision and recall are calculated using values from a confusion matrix.

For a binary classification problem, the four possible outcomes are:

Actual PositiveActual Negative
Predicted PositiveTrue PositiveFalse Positive
Predicted NegativeFalse NegativeTrue Negative

True Positive

The model predicts positive and the observation is actually positive.

False Positive

The model predicts positive, but the observation is actually negative.

False Negative

The model predicts negative, but the observation is actually positive.

True Negative

The model predicts negative and the observation is actually negative.

Precision mainly depends on true positives and false positives.

Recall mainly depends on true positives and false negatives.

A Practical Example: Fraud Detection

Consider a bank that uses a machine learning model to identify fraudulent transactions.

Suppose there are 1,000 transactions:

  • 100 are fraudulent
  • 900 are legitimate

The model initially produces the following results:

Actual FraudActual Legitimate
Predicted Fraud8040
Predicted Legitimate20860

Therefore:

TP = 80
FP = 40
FN = 20
TN = 860

Calculating Precision

Precision = TP / (TP + FP)

Precision = 80 / (80 + 40)

Precision = 80 / 120

Precision = 0.667

The model has approximately 66.7% precision.

This means that when the model flags a transaction as fraudulent, about 66.7% of those flagged transactions are actually fraudulent.

Calculating Recall

Recall = TP / (TP + FN)

Recall = 80 / (80 + 20)

Recall = 80 / 100

Recall = 0.80

The model has 80% recall.

It successfully identifies 80% of all fraudulent transactions.

Where Does the Tradeoff Come From?

Most classification models produce a probability rather than an immediate yes-or-no decision.

For example, a fraud model might produce:

Transaction A → 0.91
Transaction B → 0.73
Transaction C → 0.48
Transaction D → 0.21

You then choose a threshold to convert these probabilities into classifications.

For example:

Probability >= 0.50 → Fraud
Probability < 0.50  → Legitimate

But what happens if you change the threshold?

Suppose you lower it to:

Probability >= 0.30 → Fraud

The model will classify more transactions as fraudulent.

That can help catch fraudulent transactions that previously went undetected.

However, more legitimate transactions may also be incorrectly flagged.

This can increase recall while reducing precision.

Lowering the Classification Threshold

Suppose a model uses a threshold of 0.50.

At this threshold:

Precision = 80%
Recall = 80%

Now reduce the threshold to 0.30.

The model becomes more willing to classify transactions as fraudulent.

Imagine the results become:

True Positives = 95
False Positives = 100
False Negatives = 5

Recall becomes:

Recall = 95 / (95 + 5)
       = 95%

Recall has increased from 80% to 95%.

But precision becomes:

Precision = 95 / (95 + 100)
         ≈ 48.7%

Precision has fallen to approximately 48.7%.

The model now catches almost all fraudulent transactions, but many legitimate transactions are also being flagged.

This is the precision-recall tradeoff.

Raising the Classification Threshold

Now consider the opposite approach.

Suppose you increase the threshold from 0.50 to 0.80.

The model becomes more conservative and only labels transactions as fraudulent when it is highly confident.

This may reduce false positives.

For example:

True Positives = 60
False Positives = 10
False Negatives = 40

Precision becomes:

Precision = 60 / (60 + 10)
         ≈ 85.7%

Recall becomes:

Recall = 60 / (60 + 40)
       = 60%

Now precision has improved, but recall has fallen.

The model produces fewer incorrect fraud alerts, but it misses more fraudulent transactions.

Visualizing the Tradeoff

A precision-recall curve can help you understand how model performance changes across different classification thresholds.

Typically, as the classification threshold changes, precision and recall move in opposite directions.

There is no single threshold that is automatically best for every problem.

The right threshold depends on the consequences of false positives and false negatives.

When Is High Precision More Important?

High precision is useful when false positives are expensive or disruptive.

Examples include:

Email Spam Filtering

If a legitimate email is incorrectly classified as spam, the user may miss an important message.

Content Moderation

If legitimate content is incorrectly flagged, users may have a poor experience.

Sales Lead Qualification

A company may want to avoid sending sales teams large numbers of irrelevant leads.

In these situations, reducing false positives can be particularly important.

When Is High Recall More Important?

High recall is important when missing a positive case is particularly costly.

Examples include:

Fraud Detection

Missing fraudulent transactions can cause financial losses.

Security Threat Detection

Failing to detect a genuine security threat can have serious consequences.

Medical Screening

In many screening scenarios, missing a potentially important case can be more concerning than generating additional follow-up investigations.

The specific metric priority should always depend on the application and the cost of different errors.

The F1 Score

Sometimes you want a single metric that balances precision and recall.

The F1 score is the harmonic mean of precision and recall.

Its formula is:

F1 = 2 × (Precision × Recall)
     / (Precision + Recall)

Suppose:

Precision = 0.80
Recall = 0.60

Then:

F1 = 2 × (0.80 × 0.60)
     / (0.80 + 0.60)

F1 ≈ 0.686

The F1 score is approximately 68.6%.

The harmonic mean makes the score sensitive to situations where one metric is much lower than the other.

Precision-Recall Tradeoff vs Accuracy

Accuracy measures the percentage of all predictions that are correct.

Accuracy = (TP + TN) / (TP + TN + FP + FN)

Accuracy can be misleading when classes are highly imbalanced.

Imagine a fraud dataset containing:

9,900 legitimate transactions
100 fraudulent transactions

A model that predicts every transaction as legitimate would achieve:

Accuracy = 9,900 / 10,000
        = 99%

That sounds excellent.

But the model detects zero fraudulent transactions.

Its recall for the fraud class is:

Recall = 0 / (0 + 100)
       = 0%

This is why precision and recall are often more informative than accuracy for imbalanced classification problems.

How to Choose the Right Threshold

There is no universally correct classification threshold.

Instead, choose the threshold based on the business problem.

A useful process is:

1. Identify the Cost of False Positives

Ask:

What happens when the model predicts positive incorrectly?

2. Identify the Cost of False Negatives

Ask:

What happens when the model fails to detect a genuine positive case?

3. Compare Different Thresholds

Evaluate precision, recall, and other relevant metrics at multiple thresholds.

4. Choose a Business-Appropriate Operating Point

The best threshold is the one that produces an acceptable balance between model performance and real-world consequences.

Precision and Recall in Python

You can calculate precision and recall using scikit-learn.

from sklearn.metrics import precision_score, recall_score

y_true = [1, 1, 1, 0, 0, 0, 1, 0]
y_pred = [1, 1, 0, 0, 1, 0, 1, 0]

precision = precision_score(y_true, y_pred)
recall = recall_score(y_true, y_pred)

print("Precision:", precision)
print("Recall:", recall)

This is useful when evaluating a trained classification model.

You can also examine how the metrics change as you adjust the probability threshold.

Practical Decision Guide

SituationPrioritize
False positives are expensivePrecision
False negatives are expensiveRecall
Both errors matterF1 score
Classes are balanced and errors have similar costsAccuracy may be useful
Highly imbalanced classificationPrecision and recall
Need to compare thresholdsPrecision-recall curve

These are guidelines rather than rigid rules. The appropriate evaluation metric depends on the specific application and cost of errors.

Common Mistakes

Focusing Only on Accuracy

A high accuracy score does not necessarily mean the model is useful, especially with imbalanced data.

Assuming Higher Precision Is Always Better

Increasing precision can reduce recall. A model that almost never produces false positives may also miss many genuine positive cases.

Assuming Higher Recall Is Always Better

A model can achieve very high recall by predicting a large number of observations as positive, potentially creating an unacceptable number of false positives.

Using a Default Threshold Without Evaluation

A threshold of 0.50 is common, but it is not automatically optimal.

Ignoring Business Costs

Model evaluation should consider the real-world consequences of false positives and false negatives, not just mathematical scores.

Final Thoughts

Precision and recall provide two different perspectives on classification performance.

Precision asks:
“How reliable are my positive predictions?”

Recall asks:
“How many of the actual positive cases did my model find?”

Changing the classification threshold can shift the balance between these two metrics. Lower thresholds often make the model more sensitive to positive cases, increasing recall while potentially reducing precision. Higher thresholds can have the opposite effect.

The right balance depends on the problem.

For fraud detection, security, or many screening applications, missing positive cases may be more costly. In other applications, excessive false positives may create greater problems.

Rather than automatically optimizing for one metric, evaluate the precision-recall tradeoff against the real-world objective of your model.

Frequently Asked Questions

What is the precision-recall tradeoff?

The precision-recall tradeoff describes the relationship between precision and recall when changing a classification model’s decision threshold. Increasing recall can sometimes reduce precision, while increasing precision can sometimes reduce recall.

Which is more important, precision or recall?

Neither metric is universally more important. Precision should be prioritized when false positives are costly, while recall is more important when missing positive cases is costly.

Does increasing recall decrease precision?

Often, yes. Lowering a classification threshold can identify more actual positive cases, increasing recall, but it can also produce more false positives, which may reduce precision.

What happens when you increase the classification threshold?

A higher threshold generally makes a model more conservative about predicting the positive class. This can increase precision while reducing recall.

What is a good precision score?

There is no universal definition of a good precision score. Its usefulness depends on the application, class distribution, and cost of false positives.

What is a good recall score?

A good recall score depends on the consequences of missing positive cases. In applications where false negatives are particularly costly, a high recall may be desirable.

Is F1 score better than precision and recall?

F1 score provides a single measure that balances precision and recall, but it should not automatically replace the individual metrics. The best evaluation approach depends on the objectives of the application.

Why are precision and recall useful for imbalanced datasets?

Accuracy can appear high when one class dominates the dataset. Precision and recall focus more directly on the performance of the positive class, making them useful for many imbalanced classification problems.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top