What is the ROC curve and what does AUC represent?
Learn what the ROC curve and AUC represent, how TPR and FPR shape it, what AUC values mean, and when to use a precision-recall curve instead.
Expected Interview Answer
The ROC (Receiver Operating Characteristic) curve plots the true-positive rate against the false-positive rate as the classification threshold varies, and AUC (Area Under the Curve) is the single number summarizing that curve — the probability that the model ranks a random positive higher than a random negative.
Each point on the curve corresponds to one threshold. A model that only guesses gives a diagonal line with AUC 0.5, while a perfect ranker bows to the top-left corner with AUC 1.0. Because AUC is threshold-independent and based on ranking, it is useful for comparing classifiers, but on highly imbalanced data a precision-recall curve is often more informative since ROC can look optimistic when negatives dominate.
- Summarizes performance across all thresholds at once
- Is threshold-independent, so no single cutoff must be chosen
- AUC gives one comparable number between models
- Has a clear probabilistic ranking interpretation
- Helps choose an operating point from the curve's shape
AI Mentor Explanation
Imagine ranking every delivery by how dangerous a batter judges it, then dialing a 'play or leave' threshold from cautious to aggressive. Plotting balls correctly attacked against balls wrongly attacked as you shift the threshold traces the ROC curve; the area under it says how well the batter's danger sense separates loose balls from good ones overall.
Step-by-Step Explanation
Step 1
Get predicted probabilities
Use a classifier that outputs scores or probabilities rather than hard labels for the positive class.
Step 2
Sweep the threshold
Vary the decision threshold from 0 to 1, turning each score into a positive or negative prediction at that cutoff.
Step 3
Compute TPR and FPR
At each threshold calculate the true-positive rate (recall) and false-positive rate (FP / (FP + TN)).
Step 4
Plot the curve
Plot TPR on the y-axis against FPR on the x-axis; connecting the points across thresholds forms the ROC curve.
Step 5
Measure the area
Integrate the area under the curve to get AUC — 0.5 is random, 1.0 is perfect ranking.
What Interviewer Expects
- TPR and FPR definitions and axes
- The probabilistic ranking interpretation of AUC
- That 0.5 is random and 1.0 is perfect
- Threshold-independence as ROC's key strength
- When to prefer a precision-recall curve on imbalanced data
Common Mistakes
- Plotting precision instead of the true-positive rate
- Confusing the x-axis FPR with precision or recall
- Claiming AUC always tells you the best threshold to use
- Trusting ROC AUC on severely imbalanced data without a PR curve
- Thinking a single point, not a curve, defines the ROC
Best Answer (HR Friendly)
“The ROC curve shows how well a model separates the two classes as you loosen or tighten its decision threshold, and AUC boils that whole picture into one number. An AUC of 1.0 means perfect separation, while 0.5 is no better than a coin flip.”
Code Example
from sklearn.metrics import roc_curve, roc_auc_score
y_true = [0, 0, 1, 1, 0, 1, 1, 0]
y_scores = [0.1, 0.4, 0.35, 0.8, 0.2, 0.65, 0.9, 0.3]
fpr, tpr, thresholds = roc_curve(y_true, y_scores)
auc = roc_auc_score(y_true, y_scores)
print('AUC:', auc)
# Plot tpr vs fpr to draw the ROC curveFollow-up Questions
- How is AUC's probabilistic interpretation related to the Mann-Whitney U statistic?
- When is a precision-recall curve better than an ROC curve?
- How do you choose an operating threshold from an ROC curve?
- What does the diagonal line on an ROC plot represent?
- How does class imbalance make ROC AUC look optimistic?
MCQ Practice
1. What does the y-axis of an ROC curve represent?
ROC plots the true-positive rate (recall) on the y-axis against the false-positive rate on the x-axis.
2. An AUC of 0.5 means the model:
AUC 0.5 corresponds to the diagonal line, meaning the model cannot distinguish positives from negatives better than chance.
3. AUC can be interpreted as the probability that the model:
AUC equals the probability that a randomly chosen positive receives a higher score than a randomly chosen negative.
Flash Cards
What ROC plots — True-positive rate (y) versus false-positive rate (x) as the threshold varies.
What AUC is — Area under the ROC curve; a single 0-1 summary of ranking quality.
AUC = 0.5 — Random guessing — the model cannot separate the classes.
AUC = 1.0 — Perfect ranking — every positive scored above every negative.
ROC weakness — Can look optimistic on highly imbalanced data; use a precision-recall curve instead.