Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +918448811320
Back to Deep Learning Notes
Topic #340

Precision-Recall Curve

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

\[ \text{y-axis: Precision} = \frac{TP}{TP+FP}, \qquad \text{x-axis: Recall} = \frac{TP}{TP+FN} \]

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

Recall Precision

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.

Related DL Notes

Want to go beyond the notes?

Join Coding Hubs School of AI's Deep Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →