01 / 23

Precision, Recall
& ROC/AUC

Learn how to evaluate classification models using precision, recall, and the ROC curve: the essential metrics every analyst needs.

Business Analytics

Why Classification Metrics Matter

Imagine a model that predicts whether an email is spam or not spam. If it says "not spam" for every single email, it might still be 95% accurate: most emails are legitimate. But it catches zero spam. Accuracy alone is misleading.

The Confusion Matrix

Every binary classifier produces four outcomes. The confusion matrix organizes them into a \( 2 \times 2 \) grid that is the foundation for all classification metrics.

Actual Class Actual + Actual − Predicted Predicted + Predicted − TP True Positive FP False Positive FN False Negative TN True Negative TP = correctly flagged positive FP = incorrectly flagged positive (Type I error)

Four Outcomes Explained

TP: True Positive
Model says "spam" and it really is spam. A correct catch.
FP: False Positive
Model says "spam" but it is legitimate. A false alarm.
FN: False Negative
Model says "not spam" but it was spam. A missed catch.
TN: True Negative
Model says "not spam" and it really isn't. Correctly ignored.

What Is Precision?

Precision answers: "Of everything the model flagged as positive, how many were actually positive?" It measures the trustworthiness of positive predictions.

High precision means few false alarms. If a fraud detection system has \( \text{Precision} = 0.95 \), then 95% of its fraud alerts are truly fraudulent.

What Is Recall?

Recall (also called sensitivity or true positive rate) answers: "Of all the actual positives, how many did the model catch?"

High recall means few missed cases. If a cancer screening has \( \text{Recall} = 0.98 \), it catches 98% of true cancers.

Precision vs Recall

Precision Recall
Question How trustworthy are + predictions? How many + cases were found?
Formula \( \frac{TP}{TP+FP} \) \( \frac{TP}{TP+FN} \)
Denominator All predicted positives All actual positives
Hurt by False Positives (FP) False Negatives (FN)
Prioritize when False alarms are costly Missing cases is costly

The \(F_1\) Score: Balancing Both

When you need a single number that balances precision and recall, use the \( F_1 \) score: the harmonic mean of the two.

The harmonic mean penalizes extreme imbalance. If either precision or recall is very low, \( F_1 \) drops sharply: you cannot hide a weakness in one metric behind strength in the other.

Thresholds and Probability

Most classifiers output a probability (e.g., "72% chance of fraud"). A threshold (default \( t = 0.5 \)) converts that probability into a "yes" or "no" label.

1
Lower the threshold (e.g., \( t = 0.3 \)): more items flagged positive. Recall goes up, precision goes down.
2
Raise the threshold (e.g., \( t = 0.7 \)): fewer items flagged positive. Precision goes up, recall goes down.
3
The ROC curve visualizes model performance across all possible thresholds, so you see the full picture.

The ROC Curve

The Receiver Operating Characteristic curve plots True Positive Rate (Recall) on the y-axis against False Positive Rate on the x-axis, at every threshold.

False Positive Rate (FPR) True Positive Rate (TPR) 0 0.25 0.50 0.75 1.0 0 0.25 0.50 0.75 1.0 Random (AUC = 0.5) Good Model AUC ≈ 0.92

Understanding AUC

AUC (Area Under the Curve) is the total area beneath the ROC curve. It gives you a single number summarizing how well the model separates classes across all thresholds.

\(\text{AUC} = 1.0\)
Perfect classifier: separates all positives from all negatives with zero errors.
\(\text{AUC} = 0.5\)
No better than random guessing: the diagonal line in the ROC plot.
\(\text{AUC} < 0.5\)
Worse than random: the model's predictions are inversely correlated with reality.

When to Prioritize Which Metric

Precision
Spam filter: false alarms (good email blocked) are costly. Prioritize precision to minimize FP.
Recall
Disease screening: missing a sick patient (FN) is dangerous. Prioritize recall to catch all cases.
\(F_1\) Score
Balanced importance: when both false alarms and missed cases matter equally.
AUC
Model comparison: when you want one threshold-independent number to rank models.

How to Evaluate a Classifier

1
Build the confusion matrix. Count TP, FP, FN, and TN from your test set predictions.
2
Compute precision and recall. Use the formulas \( \frac{TP}{TP+FP} \) and \( \frac{TP}{TP+FN} \).
3
Decide which metric matters most based on business context: are false alarms or missed cases more costly?
4
Plot the ROC curve by varying the threshold and computing (FPR, TPR) at each step.
5
Calculate AUC to get a threshold-independent score. Compare models by their AUC values.

Example 1: Fraud Detection

A bank's model flags transactions as fraudulent. On a test set of 1,000 transactions, the confusion matrix is:

TP = 45 FP = 15 FN = 5 TN = 935 Pred + Pred − Actual + Actual −

Example 2: Medical Screening

A hospital tests 500 patients for a rare disease. Results:

Actually Sick Actually Healthy
Test Positive 18 (TP) 32 (FP)
Test Negative 2 (FN) 448 (TN)

Example 3: Comparing Models with ROC/AUC

FPR TPR 0 0.5 1.0 0 0.5 1.0 Model A: AUC ≈ 0.92 Model B: AUC ≈ 0.78

Common Mistakes

✕ Relying Only on Accuracy
With 95% negatives and 5% positives, predicting "negative" always gives 95% accuracy but 0% recall.
✕ Confusing Precision and Recall
Precision looks at predicted positives (denominator: TP+FP). Recall looks at actual positives (denominator: TP+FN). Mixing up the denominators changes everything.
✕ Ignoring the Business Context
Optimizing precision when recall matters (e.g., disease screening) can cause real harm. Always ask: "What is the cost of each error type?"

Summary of Key Metrics

Metric Formula Best When
Precision \( \frac{TP}{TP+FP} \) False alarms are costly
Recall \( \frac{TP}{TP+FN} \) Missing positives is costly
\(F_1\) Score \( 2 \cdot \frac{\text{Precision} \times \text{Recall}}{\text{Precision} + \text{Recall}} \) Both errors matter equally
AUC Area under ROC curve Comparing models overall
Accuracy \( \frac{\text{TP}+\text{TN}}{\text{Total}} \) Balanced classes only

Question 1 of 5

A model has \( \text{TP} = 80, \text{FP} = 20, \text{FN} = 40, \text{TN} = 860 \). What is the precision?

Question 2 of 5

In a cancer screening program, which metric should be prioritized to avoid missing sick patients?

Question 3 of 5

A model that predicts "negative" for every single case in a dataset with 5% positives will have an accuracy of 95%. What will its recall be?

Question 4 of 5

An ROC curve that hugs the top-left corner of the plot indicates:

Question 5 of 5

If \( \text{Precision} = 0.60 \) and \( \text{Recall} = 0.90 \), what is the \( F_1 \) score?