Skip to content
ML Visualization

ROC Curves & AUC

Data Prep & Model EvaluationIntermediate~7 min

ROC Curves & AUCVisualize the full threshold tradeoff in one curve.

The ROC curve traces how true-positive and false-positive rates trade off across every possible threshold. The area under it (AUC) summarizes the classifier’s ranking quality in a single number.

  • ROC swept so far
  • PR swept so far
  • Not yet reached
  • Operating point
  • Cost-optimal
AUC (ROC)0.940
Average precision (PR)0.941
01

ROC controls

Data
Scenario

Half the cases are positive and both mistakes cost the same — the textbook setting where 0.5 is defensible.

0.60
50%

Separability moves both curves. Balance barely touches the ROC and wrecks the PR curve — that gap is the whole point of the second panel.

Model
1.00
Playback
Step 0 / 100
Speed
  1. Strict (t → 1)
  2. Balanced
  3. Permissive (t → 0)

Step 0 of 100 — t = 1.00 — TPR 2% (3/200), FPR 0% (0/200) · precision 100%, recall 2%

Press play: the threshold falls from 1 to 0 and both curves draw themselves from the origin, one point per rung, while the histogram split slides with them.

Break it

The idea in plain words

The ROC curve traces how the true-positive and false-positive rates trade off across everythreshold. The area under it (AUC) summarizes ranking quality in a single number: 1.0 is perfect, 0.5 is a coin flip.

Pull the two score distributions apart and the ROC morphs from the useless diagonal to the perfect corner. It complements precision–recall, though on heavily imbalanced data a high AUC can still hide poor precision.

Now, the math

The ROC plots the true-positive rate against the false-positive rate:

TPR=TPTP+FN,FPR=FPFP+TN\text{TPR} = \frac{TP}{TP+FN},\qquad \text{FPR} = \frac{FP}{FP+TN}
TPR\text{TPR}
recall — the vertical axis of the ROC.
FPR\text{FPR}
false-alarm rate — the horizontal axis.
AUC\text{AUC}
area under the curve — probability a random positive outranks a random negative.
Show the derivation

Sweeping the threshold from high to low traces the curve from the origin to (1,1). AUC equals the probability that a randomly chosen positive scores higher than a randomly chosen negative, so it measures the model’s ranking independent of any single threshold.

Trace it by hand

Six scored points: positives at 0.9, 0.7, 0.4 and negatives at 0.6, 0.3, 0.1, with score at or above t predicting positive. We read TPR and FPR at two thresholds, then get AUC two independent ways. Rates verified with the site's threshold engine; rounded to 2 decimals.

  1. A strict threshold, t = 0.65

    TPR=TPTP+FN=230.67,FPR=FPFP+TN=03=0\text{TPR} = \frac{TP}{TP + FN} = \frac{2}{3} \approx 0.67, \qquad \text{FPR} = \frac{FP}{FP + TN} = \frac{0}{3} = 0

    Only 0.9 and 0.7 clear the bar — both positives, no false alarms. This is the ROC point (0, 0.67).

  2. A lenient threshold, t = 0.35

    TPR=33=1,FPR=130.33\text{TPR} = \frac{3}{3} = 1, \qquad \text{FPR} = \frac{1}{3} \approx 0.33

    Now every positive is caught, but the negative at 0.6 comes along as a false alarm: ROC point (0.33, 1).

  3. Area under the full step curve

    AUC=1323+231=29+69=890.89\text{AUC} = \tfrac{1}{3} \cdot \tfrac{2}{3} + \tfrac{2}{3} \cdot 1 = \tfrac{2}{9} + \tfrac{6}{9} = \tfrac{8}{9} \approx 0.89

    Sweeping every threshold traces a staircase of height two thirds over the first third of the FPR axis and height 1 over the rest.

  4. Same number by counting pairs

    AUC=8 correctly ranked pairs9 pos-neg pairs=890.89\text{AUC} = \frac{8 \text{ correctly ranked pairs}}{9 \text{ pos-neg pairs}} = \frac{8}{9} \approx 0.89

    Of the 3 times 3 positive-negative pairs, only one is misranked: the positive at 0.4 scores below the negative at 0.6.

What just happened: The two operating points (0, 0.67) and (0.33, 1) are just samples of one curve, and its area 8/9 has a concrete meaning: 8 of the 9 positive-negative pairs are ranked correctly. AUC grades the ranking itself, before any threshold is chosen.

Now Break It

Try this: On imbalanced data AUC looks great while precision at the useful threshold is terrible.

Control: Class balance slider (set imbalanced)

What happens: AUC can mislead! On imbalanced data a high AUC hides poor precision where it matters.

Where roc curves & auc is used

An ROC curve visualizes a classifier's performance across every possible decision threshold at once, rather than at a single cutoff. It plots the true positive rate against the false positive rate as the threshold sweeps from strict to lenient, tracing the full tradeoff between catching positives and raising false alarms. The area under the curve, or AUC, condenses this into one number with an intuitive meaning: it is the probability that the model ranks a randomly chosen positive higher than a randomly chosen negative. An AUC of 0.5 is no better than random guessing and 1.0 is perfect ranking. Because it is threshold-independent, AUC is popular for comparing models in medical diagnostics and credit scoring, where the final operating threshold is chosen later.

A major pitfall is relying on ROC AUC for highly imbalanced data, where it can look reassuringly high even when the model performs poorly on the rare class. The false positive rate has a large negative denominator, so many false positives barely move the curve; a precision-recall curve is more informative in that setting because it focuses on the positive class. Another misconception is reading AUC as accuracy or as a probability of being correct; it is a ranking measure and says nothing about calibration or the quality of predictions at any particular threshold. A model can have excellent AUC yet still need a carefully chosen threshold to be useful in practice.

Frequently asked questions

What does AUC actually measure?
AUC is the area under the ROC curve, and it equals the probability that the model assigns a higher score to a randomly chosen positive example than to a randomly chosen negative one. It measures ranking quality across all thresholds, not accuracy at any single cutoff. A value of 0.5 is random and 1.0 is perfect.
What is the difference between an ROC curve and a precision-recall curve?
An ROC curve plots true positive rate against false positive rate, while a precision-recall curve plots precision against recall. On imbalanced data the precision-recall curve is usually more informative because it focuses on the positive class and is not flattered by the many easy negatives that keep the false positive rate low.
Is a higher AUC always better?
Higher AUC means better overall ranking, but it does not guarantee good performance at the threshold you will actually deploy, nor that predicted probabilities are well calibrated. On severely imbalanced problems AUC can look strong while precision is poor, so pair it with metrics that match your real objective.
Why is an AUC of 0.5 considered random?
An AUC of 0.5 means the model is no better than chance at ranking a positive above a negative, which is what a coin flip would achieve. The diagonal line on the ROC plot represents this random baseline, and curves above it indicate genuine discriminative ability.
Can AUC be misleading?
Yes. On imbalanced datasets a high AUC can mask weak detection of the rare class because false positives barely affect the false positive rate. It also says nothing about calibration or performance at a specific threshold, so it should not be the only metric you report.

Written & reviewed by the ML Visualization team · Last updated .