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.
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:
| Threshold | FP | FN | Cost |
|---|---|---|---|
| 0.5 | 10 | 20 | £220,000 |
| 0.2 | 40 | 6 | £140,000 (best) |
| 0.1 | 90 | 2 | £200,000 |
The lowest cost is at 0.2, close to the theoretical 0.167. Going lower produces too many false alarms.
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
Expected cost
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.