intermediatemachine-learning

ROC Curve and AUC

A tool to see how well your classifier separates the two classes at every possible threshold.

Key Points

What it is

ROC (Receiver Operating Characteristic) curve plots the True Positive Rate (recall) against the False Positive Rate (1 - specificity) as you vary the classification threshold. Each point on the curve corresponds to a different threshold. The AUC (Area Under the Curve) is a single number that summarizes the curve – it tells you the probability that your model will rank a random positive example higher than a random negative example. AUC of 1.0 is perfect, 0.5 is random guessing.

Why it exists

A single threshold gives you one point (precision and recall at that threshold). But different applications want different tradeoffs. A cancer screener might accept more false positives to catch almost all cancers (low threshold). A spam filter might prefer fewer false positives even if it misses some spam (high threshold). The ROC curve shows you the entire range of possibilities so you can choose the threshold that matches your cost. AUC gives you a single number to compare models without picking a threshold first.

What it measures

The ROC curve measures the model's ability to separate the two classes. A steep curve near the top left means the model can get high recall without many false positives. AUC measures the model's ranking quality: if you pick one random positive and one random negative, what is the probability that the model assigns a higher score to the positive? An AUC of 0.8 means 80% of the time, the positive gets a higher score than the negative.

Intuition

Imagine you have a test that gives a score from 0 to 100 for a disease. Healthy people tend to score low, sick people high. But there is overlap. You need to choose a cutoff: anyone above the cutoff is diagnosed as sick. ROC curve: For every possible cutoff, you calculate two rates: what fraction of sick people you correctly diagnose (TPR) and what fraction of healthy people you falsely diagnose (FPR). Plot them. A perfect test would have TPR=1 with FPR=0 (top left corner). A useless test gives a diagonal line (TPR = FPR). The area under the curve tells you how far your test is from useless. A doctor uses the ROC curve to choose a cutoff that balances missing cases vs. false alarms.

Formulas

True Positive Rate (Recall)

TPR=TPTP+FNTPR = \frac{TP}{TP + FN}
  • TPR — same as recall – how many positives you catch

False Positive Rate

FPR=FPFP+TNFPR = \frac{FP}{FP + TN}
  • FPR — false alarm rate – proportion of negatives you incorrectly call positive

AUC interpretation

AUC=P(scorepositive>scorenegative)\text{AUC} = P(\text{score}_{positive} > \text{score}_{negative})
  • P(...) — probability that a randomly chosen positive has a higher predicted score than a randomly chosen negative

When to use

When not to use

Common mistakes

In practice

In scikit-learn: `from sklearn.metrics import roc_curve, roc_auc_score`. Get probabilities: `y_scores = model.predict_proba(X_test)[:, 1]`. Then `fpr, tpr, thresholds = roc_curve(y_test, y_scores)`. Plot fpr vs tpr. Compute AUC: `auc = roc_auc_score(y_test, y_scores)`. For multiclass, use `roc_auc_score(y_test, y_scores, multi_class='ovo')`. A common plot also includes the diagonal line (random classifier) for reference.

Was this concept helpful?

Spot an error or gap? Suggest an edit →

Related concepts

precision-recallconfusion-matrixclassification-threshold
Chirp at me!