๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #151

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.

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Precision-Recall Curve โ€“ FAQs

Quick answers about learning Precision-Recall Curve in Deep Learning.

This free note from CodingNow 2.0 explains Precision-Recall Curve in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Precision-Recall Curve, is 100% free with no signup required.
With focused practice, most students grasp Precision-Recall Curve in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now