Precision, Recall
& ROC/AUC
Learn how to evaluate classification models using precision, recall, and the ROC curve: the essential metrics every analyst needs.
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.
Four Outcomes Explained
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.
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.
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.
When to Prioritize Which Metric
How to Evaluate a Classifier
Example 1: Fraud Detection
A bank's model flags transactions as fraudulent. On a test set of 1,000 transactions, the confusion matrix is:
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
Common Mistakes
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?