Interactive guide

ROC, AUC, and the threshold

By convention, a classifier calls anything scoring above 0.5 "positive." That default is only correct in one specific situation. Below, one fixed model is put to work in three settings, same predictions, same ROC curve, same AUC, and only the cost of being wrong changes. Watch what that does to the right threshold.

Four outcomes, two kinds of mistake

Every prediction at a given threshold lands in one of four boxes. Two of them are mistakes, and they fail in opposite directions.

A Type I error is a false positive: the model raised a flag on something that was actually fine. The cost lands on whoever, or whatever, got flagged by mistake: wasted effort at best, wrongful punishment of an innocent case at worst.

A Type II error is a false negative: the model stayed quiet on something it should have caught. The cost lands later, and it compounds: a real problem keeps going unaddressed until someone finds it the hard way.

Accuracy treats these as interchangeable: one wrong answer is one wrong answer. In the real world, they almost never cost the same, and mixing them up is how a "0.5 threshold" quietly becomes the wrong call.

What ROC and AUC actually show

Slide the threshold from 1 down to 0 and, at every step, plot the true positive rate against the false positive rate. That trace is the ROC curve. The AUC is the area under it: the probability the model ranks a random positive case above a random negative one. Notice what AUC doesn't include: it says nothing about which threshold to use. That's a separate decision, made below.

Predicted 1
Predicted 0
Actual 1
True Positive
False Negative Type II
Actual 0
False Positive Type I
True Negative

The jargons, in one example

Say a test screens 100 people: 20 are actually sick, 80 are healthy. It flags 22 people positive: correctly catching 18 of the 20 sick people, and wrongly flagging 4 of the 80 healthy ones. That's TP = 18, FN = 2, FP = 4, TN = 76. Every term below is computed from that same 100 people.

Threshold

The cutoff score above which the model calls something positive. This whole page is about picking that number well.

TPR Recall · Sensitivity

Of everyone truly positive, how many did it catch?

TPR= TP / (TP+FN) = 18 / 20 = 90%
FPR

Of everyone truly negative, how many did it wrongly flag?

FPR= FP / (FP+TN) = 4 / 80 = 5%
Specificity = 1 − FPR

Of everyone truly negative, how many did it correctly clear? The mirror image of FPR, common in medical stats.

Spec.= TN / (TN+FP) = 76 / 80 = 95%
Precision

Of everyone it flagged positive, how many actually were?

Prec.= TP / (TP+FP) = 18 / 22 ≈ 82%
Accuracy

Of everyone, how many did it get right, positive or negative?

Acc.= (TP+TN) / N = 94 / 100 = 94%
ROC curve

Plot TPR against FPR at every possible threshold, from 1 down to 0. Traces the full tradeoff between catching positives and raising false alarms.

AUC

Area under that curve. The probability the model ranks a random sick person above a random healthy one, independent of any single threshold.

Here is that one model: 440 labeled examples, AUC = 0.817, fixed from here on. Three price tags, three right answers.

Case 1 · The baseline

Equal-cost classifier

Positive means the model flags an item for manual review. If it flags something that didn't need it (a false positive), someone wastes a few minutes reviewing it for nothing. If it misses something that did need review (a false negative), that item just gets caught a little later, at about the same cost. Neither mistake is worse than the other here.

Type I · false positive 1unit of harm
A false alarm: a bit of wasted review time.
Type II · false negative 1unit of harm
A miss, caught later, the same wasted effort either way.
Predicted Flagged
Predicted Cleared
Actual positive
0 True Positive
0 False Negative
Actual negative
0 False Positive
0 True Negative
0.50 Drag to change the classification threshold from 0 to 1.
Accuracy
TP + TNN
=
0 + 0 0
=
0%
Precision
TPTP + FP
=
0 0
=
0%
Recall (TPR)
TPTP + FN
=
0 0
=
0%
False positive rate
FPFP + TN
=
0 0
=
0%
ROC curve AUC 0.817

y = TPR = TP / (TP+FN) x = FPR = FP / (FP+TN)

1 0 1 False positive rate (x) True positive rate (y)

model   random guess (y = x)

Total cost by threshold optimal ≈ 0.50
cost(t) = FP(t)×1 + FN(t)×1 = 0×1 + 0×1 = 0
0 Total cost (y) 0.00 0.50 1.00 Decision threshold (x)

cost at threshold   lowest-cost threshold

Total cost at this threshold
cost = FP×1 + FN×1 = 0×1 + 0×1 = 0 units

Here the two error types are priced the same, so the threshold that minimizes total cost lands exactly on 0.50. This is the only one of the three cases where the textbook default is actually the right answer.

Case 2 · Type I error is expensive

Criminal trial verdict

Positive means the model votes “guilty.” If it wrongly convicts an innocent person (a false positive), that harm is severe and often impossible to undo. If it wrongly lets a guilty person walk free (a false negative), that's bad too, but the justice system is deliberately designed to treat it as the lesser harm.

Type I · false positive 8units of harm
Convicting an innocent person: often irreversible, and the system cannot easily undo it. 8.0× costlier than a false negative here
Type II · false negative 1unit of harm
Acquitting a guilty person, bad, but by design the lesser harm to a justice system.
Predicted Convicted
Predicted Acquitted
Actual positive
0 True Positive
0 False Negative
Actual negative
0 False Positive
0 True Negative
0.50 Drag to change the classification threshold from 0 to 1.
Accuracy
TP + TNN
=
0 + 0 0
=
0%
Precision
TPTP + FP
=
0 0
=
0%
Recall (TPR)
TPTP + FN
=
0 0
=
0%
False positive rate
FPFP + TN
=
0 0
=
0%
ROC curve AUC 0.817

y = TPR = TP / (TP+FN) x = FPR = FP / (FP+TN)

1 0 1 False positive rate (x) True positive rate (y)

model   random guess (y = x)

Total cost by threshold optimal ≈ 0.50
cost(t) = FP(t)×8 + FN(t)×1 = 0×8 + 0×1 = 0
0 Total cost (y) 0.00 0.50 1.00 Decision threshold (x)

cost at threshold   lowest-cost threshold

Total cost at this threshold
cost = FP×8 + FN×1 = 0×8 + 0×1 = 0 units

Because false positives are far costlier, total harm keeps falling well past 0.50, the optimum sits around 0.76. Convicting at 0.50 confidence would rack up much more damage than the model's ROC curve alone would suggest.

Case 3 · Type II error is expensive

COVID-19 screening test

Positive means the model flags the patient as infected with COVID-19. If it misses a real case (a false negative), that person walks away thinking they're clear, keeps going to work and seeing others, and unknowingly spreads the virus further. If it flags a healthy patient by mistake (a false positive), the only cost is a few days of unnecessary isolation and a confirmatory retest.

Type I · false positive 1unit of harm
An unnecessary isolation period and retest: inconvenient, but reversible.
Type II · false negative 8units of harm
A missed infection: the patient unknowingly keeps spreading the virus. 8.0× costlier than a false positive here
Predicted Flagged as infected
Predicted Cleared as healthy
Actual positive
0 True Positive
0 False Negative
Actual negative
0 False Positive
0 True Negative
0.50 Drag to change the classification threshold from 0 to 1.
Accuracy
TP + TNN
=
0 + 0 0
=
0%
Precision
TPTP + FP
=
0 0
=
0%
Recall (TPR)
TPTP + FN
=
0 0
=
0%
False positive rate
FPFP + TN
=
0 0
=
0%
ROC curve AUC 0.817

y = TPR = TP / (TP+FN) x = FPR = FP / (FP+TN)

1 0 1 False positive rate (x) True positive rate (y)

model   random guess (y = x)

Total cost by threshold optimal ≈ 0.50
cost(t) = FP(t)×1 + FN(t)×8 = 0×1 + 0×8 = 0
0 Total cost (y) 0.00 0.50 1.00 Decision threshold (x)

cost at threshold   lowest-cost threshold

Total cost at this threshold
cost = FP×1 + FN×8 = 0×1 + 0×8 = 0 units

Because false negatives are far costlier, total harm keeps falling well before 0.50, the optimum sits around 0.28. Screening at 0.50 confidence would let many real infections slip through undetected.

A teaching tool: the courtroom and screening examples illustrate asymmetric cost, not legal or medical guidance. Threshold choices in real systems should involve the people who bear the cost of each error.