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
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
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?