Threshold Tuning

0.5 is a default, not a decision. Set what each kind of mistake costs and watch the cheapest threshold move away from it.

Threshold Tuning

This module needs JavaScript: the numbers are computed in the page rather than recorded.

Worth knowing

0.5 is where predict() happens to cut. It is not derived from your problem.
The optimal threshold depends on the cost of each error and on the class balance, neither of which the model knows.
Tune the threshold on validation data, not on the test set, or you have tuned on the thing you are reporting.
A model whose scores are not calibrated still ranks correctly, so threshold tuning works even when the probabilities are wrong.

Overview

Many classifiers output a score, and a threshold turns it into a positive or negative decision. Lowering the threshold usually catches more positives while creating more false alarms; the score ranking stays fixed, so ROC AUC does not change.

In this guide
  1. What the threshold changes
  2. Let error costs guide the cutoff
  3. Explore the cost curve
  4. When costs are hard to estimate
  5. Worked example
  6. Keep threshold selection honest
  7. Sources and next steps

The familiar 0.5 is a default decision rule, not a universal optimum. It is justified by calibrated probabilities and equal costs for false positives and false negatives. If the scores are not calibrated, the numerical threshold should not be interpreted as a probability.

Let error costs guide the cutoff

For a case with calibrated positive probability p, predicting positive has expected cost (1 - p) C_FP; predicting negative has expected cost p C_FN. Choose positive when the first is smaller:

(1 - p) C_FP < p C_FN

Solving gives p > C_FP / (C_FP + C_FN). If a missed positive costs 20 and a false alarm costs 1, the cost-based threshold is about 0.048. If a false alarm costs 50 and a miss costs 1, it is about 0.980. These are starting points for calibrated probabilities; operational limits and model uncertainty still matter.

Explore the cost curve

The chart compares total error cost across thresholds for its fixed example dataset. Change Cost of a miss (false negative) and Cost of a false alarm (false positive). When missing a positive becomes more expensive, the minimum-cost point moves toward a lower threshold. When false alarms become expensive, it moves higher. This curve illustrates the trade-off; it is not a guarantee that the same threshold will be best on your data.

When costs are hard to estimate

Choose a measurable operating requirement instead:

  • Recall target: find a threshold that catches at least the required share of positives, then inspect the resulting false alarms.
  • Precision target: require a minimum fraction of alerts to be correct, then measure how many positives are missed.
  • Review capacity: take the highest-scoring cases up to the team’s available capacity.
  • F-score: use F1 when precision and recall matter similarly, or F-beta when one matters more. Select the score on validation data.

None of these choices is value-free. State the constraint and show the resulting confusion matrix so readers can see the practical workload and error counts.

Worked example

Suppose a screening model ranks 1,000 patients, 100 of whom have a condition. At threshold 0.5 it flags 40 patients and catches 30 cases: precision is 30/40 = 75% and recall is 30/100 = 30%. Lowering the threshold might flag 120 and catch 75: recall rises to 75%, while precision becomes 75/120 = 62.5%. Whether that is better depends on follow-up capacity and the relative harm of a missed case and an unnecessary review.

Keep threshold selection honest

Tune the threshold using validation data or out-of-fold predictions, then evaluate the chosen rule once on the test set. Picking a threshold on the test set and reporting its score makes the test result optimistic. If the class prevalence or error costs change in production, review the operating point again.

Cost-derived thresholds require probabilities that represent real frequencies; check calibration or calibrate on separate validation data. Threshold tuning cannot repair poor ranking, missing features, or a model that does not generalize.

Sources and next steps

Check yourself

0 of 3

Answer without scrolling back up.

  1. Where does the 0.5 default threshold come from?

  2. If a miss costs ten times a false alarm, roughly what threshold does the cost formula give?

  3. How does threshold tuning differ from calibration?

Cheat sheet

Threshold Tuning

Slide the classification threshold from zero to one and watch precision, recall and cost shift. Find the cutoff that fits your problem.

MACHINE LEARNING · vizlearn.in/machine_learning/threshold_tuning.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.

Teaching a course with this? Individual teachers can use it freely; for a whole department or programme, see institutional licences.