ROC Curve and AUC — ML Technical Interview Questions & Answers
Visualizing classifier performance across thresholds.
ROC Curve and AUC
- Simple meaning: ROC plots true-positive rate vs false-positive rate as you slide the probability threshold. AUC is the area under that curve — 1.0 is perfect ranking, 0.5 is random.
- Picture: You sort students by P(fail). A good model puts real fails near the top. AUC asks: if I pick one fail and one pass, how often is the fail scored riskier?
- Useful when you care about ranking / thresholds. Less intuitive for a teacher than a confusion matrix at one threshold — show both.
- Trap: AUC on a 1% class without also showing precision-recall (PR curve is often kinder to rare fails). Trap: AUC = accuracy (they are not the same).
Technical Interview Tip: Slide the threshold. AUC = how well you rank positives vs negatives.
Code Examples for ROC Curve and AUC
ROC Curve and AUC — working example
# ROC idea: vary threshold on scores
y_true = [0, 0, 1, 1]
scores = [0.1, 0.4, 0.35, 0.8]
def tpr_fpr(threshold):
pred = [1 if s >= threshold else 0 for s in scores]
tp = sum(t == 1 and p == 1 for t, p in zip(y_true, pred))
fp = sum(t == 0 and p == 1 for t, p in zip(y_true, pred))
fn = sum(t == 1 and p == 0 for t, p in zip(y_true, pred))
tn = sum(t == 0 and p == 0 for t, p in zip(y_true, pred))
tpr = tp / (tp + fn)
fpr = fp / (fp + tn)
return tpr, fpr
for thr in (0.3, 0.5, 0.75):
print(thr, tpr_fpr(thr))
# Boosting: train trees sequentially on residuals / hard examplesROC Curve and AUC — rOC plots TPR vs FPR across thresholds; AUC summarizes ranking quality. Boosting builds strong learners from weak ones.
How to Explain ROC Curve and AUC to an Interviewer
What is AUC?
Area under the ROC curve Ranking quality
AUC 0.5?
No better than random ranking