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

ROC Curve

The ROC curve (Receiver Operating Characteristic) visualizes the tradeoff between catching true positives and accidentally flagging false positives, across every possible classification threshold — not just one fixed cutoff.

What's Plotted

\[ \text{y-axis: True Positive Rate (Recall)} = \frac{TP}{TP+FN}, \qquad \text{x-axis: False Positive Rate} = \frac{FP}{FP+TN} = 1-\text{Specificity} \]

Each point on the curve corresponds to one specific classification threshold — sweeping the threshold from 1 down to 0 traces out the entire curve, showing exactly how TPR and FPR trade off against each other at every possible operating point.

Reading the Curve

False Positive Rate True Positive Rate random guessing good classifier

A curve bowing toward the top-left corner (high TPR, low FPR) indicates a good classifier; the diagonal represents a classifier no better than random guessing.

Why the Curve Bows Toward the Top-Left for a Good Model

A perfect classifier would achieve TPR=1 (catches every true positive) at FPR=0 (never falsely flags a negative) simultaneously — the top-left corner of the plot. A model that's genuinely better than random guessing can achieve a high TPR while keeping FPR relatively low, producing a curve that bows toward that ideal corner; a model no better than random guessing traces the diagonal line, since raising the threshold to catch more true positives inevitably catches proportionally just as many false positives.

Code

from sklearn.metrics import roc_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])   # predicted probabilities

fpr, tpr, thresholds = roc_curve(y_true, y_scores)
print("FPR:", fpr)
print("TPR:", tpr)
print("Thresholds:", thresholds)

Common Mistakes

  • Using the ROC curve as the primary evaluation tool for a severely imbalanced dataset — because FPR's denominator (\(FP+TN\)) is dominated by the (typically much larger) negative class, ROC curves can look deceptively good even when precision is actually poor; the Precision-Recall curve (next note) is often more informative in this specific situation.
  • Confusing the ROC curve with a single number — the curve itself shows a full range of tradeoffs; ROC-AUC (the next note) is what condenses it into one summary value.

Interview Relevance

Q: "What does the ROC curve show that a single precision/recall number at one threshold doesn't?" It shows the full tradeoff between true positive rate and false positive rate across every possible classification threshold, rather than committing to one specific cutoff. This lets you compare classifiers' overall discriminative ability independent of any particular threshold choice, and helps you pick an appropriate threshold for a specific deployment's cost tradeoffs.

Practice Question

Why does a classifier's ROC curve trace the diagonal line if it's no better than random guessing?

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 →