The Precision-Recall curve plots precision against recall across every classification threshold โ a close cousin of the ROC curve, but one that reveals problems on imbalanced datasets that ROC can hide.
What's Plotted
As with the ROC curve, each point corresponds to one specific threshold โ sweeping the threshold traces the full curve, showing exactly how precision and recall trade off (as introduced conceptually in Precision & Recall).
Why It's More Informative Than ROC for Imbalanced Data
The ROC curve's false positive rate has \(TN\) in its denominator (\(\frac{FP}{FP+TN}\)) โ on a heavily imbalanced dataset with a huge number of true negatives, even a substantial number of false positives can look tiny relative to that huge \(TN\), making FPR (and therefore the ROC curve) look deceptively good. Precision's denominator (\(TP+FP\)) doesn't include \(TN\) at all โ it directly reflects how many of the model's positive predictions were wrong, regardless of how many negatives exist overall. This makes the PR curve substantially more sensitive to, and more honest about, performance specifically on the minority (positive) class.
Diagram
Precision typically starts high (at low recall/conservative thresholds) and falls as the threshold is lowered to catch more true positives, inevitably including more false positives too.
Code
from sklearn.metrics import precision_recall_curve
import numpy as np
y_true = np.array([1,1,1,1,0,0,0,0])
y_scores = np.array([0.9, 0.8, 0.6, 0.4, 0.7, 0.3, 0.2, 0.1])
precision, recall, thresholds = precision_recall_curve(y_true, y_scores)
print("Precision:", precision)
print("Recall:", recall)
Common Mistakes
- Defaulting to the ROC curve for every task without considering class balance โ on severely imbalanced data (common in fraud detection, rare disease screening, anomaly detection), the PR curve is generally the more honest and actionable choice.
- Reading the PR curve's shape the same way as the ROC curve โ a good PR curve stays high (near precision=1) across as much of the recall range as possible, whereas a good ROC curve bows toward the top-left corner; the "good" direction differs between the two plots.
Interview Relevance
Q: "Why might you prefer a Precision-Recall curve over an ROC curve for a fraud detection model?" Fraud datasets are typically severely imbalanced (fraud cases are rare). ROC's false positive rate is computed relative to the (huge) number of true negatives, which can make even a meaningful number of false positives look negligible โ producing a deceptively good-looking ROC curve. Precision directly reflects how many flagged transactions were actually fraudulent, giving a more honest picture of real-world performance on the rare, high-stakes positive class.
Practice Question
Explain, using the formulas for FPR and precision, why the PR curve is more sensitive to poor performance on the minority class than the ROC curve.