Lesson 4.9 · 9 min read · about 50 min to master at a very slow pace

Threshold Selection and Classification Costs

When a miss and a false alarm cost different amounts, choose the threshold that minimises expected cost. The theory, a worked table, and how to choose it without leaking the test set.

Not startedJump to quiz

0.5 is a choice, not a law

The default "predict 1 if " minimises the number of mistakes when both kinds cost the same. When they don't, pick the threshold that minimises expected cost:

The theoretical threshold

For a single case with (well-calibrated) probability : alerting costs in expectation; not alerting costs . Alert when the second is bigger:

Cost-optimal threshold

If a miss is costlier than a false alarm, the threshold moves down, so you flag more cases.

Worked example: pollution alerts

A false alarm costs £2,000; a missed dangerous reading costs £10,000. Theory: alert if .

Empirically, on 1,000 validation cases:

ThresholdFPFNCost
0.51020£220,000
0.2406£140,000 (best)
0.1902£200,000

The lowest cost is at 0.2, close to the theoretical 0.167. Going lower produces too many false alarms.

1001502002503000.10.20.30.40.5threshold ttotal cost (£k)theory: 0.167

The same logic applies when the score is a regression prediction: e.g. alert when predicted CO exceeds , where the real event is CO above a legal limit of 5. Because misses are costlier, the best ends up a little below 5: alert slightly early.

Choose the threshold on validation data

The threshold is a hyperparameter. Choosing the cost-minimising threshold on the test set and reporting the test cost leaks the test set: the reported cost is optimistic. Pick it by cross-validation or on a validation set; test once. Choosing it on training predictions is also optimistic, because the model is overconfident on data it was fitted to.

Cheatsheet

Cost-optimal threshold

Alert if . Costlier misses → lower threshold.

Expected cost

; choose on validation data.

See every cheatsheet by category →

Check your understanding

Score 75% or more to master this lesson and earn XP. Answer first, then check.

Q1calculateA false positive costs 1 and a false negative costs 9. At threshold 0.5 there are 5 FP and 10 FN; at 0.2 there are 25 FP and 3 FN. Which threshold has the lower cost?
Q2calculateA false positive costs £500 and a false negative £1,500. With well-calibrated probabilities, which threshold minimises expected cost?
Q3applyA missed diagnosis is 20 times as costly as a false alarm. Roughly where should the threshold be?
Q4diagnoseA team picks the threshold that minimises cost on the test set and reports that cost as its expected cost in production. What's wrong?
Q5conceptIf a false negative costs more than a false positive, which way should the threshold move from 0.5?