close
Skip to content
ML Visualization

The Decision Threshold

Data Prep & Model EvaluationIntermediate~7 min

The Decision Threshold — A classifier outputs scores; the decision threshold is the cut-off that turns a score into a class. Moving it trades false positives against false negatives, and the optimal threshold depends on the relative cost of each error, not a default of 0.5.

Frame it as a medical test: two overlapping score distributions and a draggable threshold. Turn the dial on how bad a miss is, and the optimal cut-off slides to match — proving 0.5 is rarely the right answer.

  • Healthy (−)
  • Disease (+)
  • Your threshold
  • Cost-optimal

The same 10 cases, judged three ways (click a row to cut there)

scoreactualt = 0.30t = 0.70t = 1.00
0.83disease++
0.73disease++
0.65disease+
0.59disease+
0.53healthy+
0.49disease+
0.41healthy+
0.31healthy+
0.23healthy
0.14healthy
t=0.30: P 63% · R 100%t=0.70: P 100% · R 40%t=1.00: P 100% · R 0%

Green is a correct call, red a wrong one. Precision and recall swap places between the two fixed columns without a single number in the model changing.

01

Threshold 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%
Model
1.00
Cost at your t197
Cheapest at t0.47 → 49

Raise the cost of a miss and the dashed optimum slides left to catch more cases. 0.5 is only the right answer while both mistakes cost the same.

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

Step 0 of 100 — t = 1.00 — flags 3 of 400 cases: 3 real, 0 false alarms, and 197 missed. Cost 1·0 + 1·197 = 197 (cheapest possible 49 at t = 0.47)

Break it

The idea in plain words

A classifier outputs a score; the threshold turns that score into a decision. The default 0.5 is rarely right — the best cut-off depends on the consequences. Frame it as a medical test: missing a disease (a false negative) is usually far costlier than a false alarm.

Turn up the cost of a miss and the optimal threshold slides lower to catch more cases. It’s the same TP/FP/FN/TN tradeoff from the confusion matrix, now weighted by what each error actually costs.

Now, the math

Pick the threshold that minimizes expected cost, not error count:

E[cost]=cFPFP+cFNFN\mathbb{E}[\text{cost}] = c_{FP}\cdot FP + c_{FN}\cdot FN
cFPc_{FP}
the cost of a false positive (false alarm).
cFNc_{FN}
the cost of a false negative (a miss).
▸ Show the derivation

The optimal threshold is where the marginal cost of catching one more positive equals the marginal cost of the false positives it admits. As the miss cost rises, that balance point shifts down, so the model flags more cases — exactly what a screening test wants.

Trace it by hand

The same ten scored predictions from the precision-recall example — positives at 0.9, 0.8, 0.6, 0.4, 0.2 and negatives at 0.7, 0.55, 0.35, 0.25, 0.1 — now cut at t = 0.3 versus t = 0.7, then costed with a false alarm at 1 and a miss at 5. Counts and costs verified with the site's threshold engine; rounded to 2 decimals.

  1. Low threshold, t = 0.3: cast a wide net

    TP=4,  FP=3,  FN=1:P=470.57,R=45=0.8TP = 4, \; FP = 3, \; FN = 1: \qquad P = \tfrac{4}{7} \approx 0.57, \qquad R = \tfrac{4}{5} = 0.8

    Everything scoring 0.3 or more is flagged — 7 points. Recall jumps to 0.8 but 3 of the 7 flags are false alarms.

  2. High threshold, t = 0.7: only sure bets

    TP=2,  FP=1,  FN=3:P=230.67,R=25=0.4TP = 2, \; FP = 1, \; FN = 3: \qquad P = \tfrac{2}{3} \approx 0.67, \qquad R = \tfrac{2}{5} = 0.4

    Same model, same scores — precision rose from 0.57 to 0.67 while recall fell from 0.8 to 0.4.

  3. Price the errors at t = 0.3

    E[cost]=cFPFP+cFNFN=13+51=8\mathbb{E}[\text{cost}] = c_{FP} \cdot FP + c_{FN} \cdot FN = 1 \cdot 3 + 5 \cdot 1 = 8

    A medical-test framing: a miss costs 5 times a false alarm.

  4. Price the errors at t = 0.7

    E[cost]=11+53=16\mathbb{E}[\text{cost}] = 1 \cdot 1 + 5 \cdot 3 = 16

    The default t equals 0.5 lands in between at 1 times 2 plus 5 times 2 equals 12 — also beaten by the low threshold.

What just happened: Raising the threshold from 0.3 to 0.7 traded recall (0.8 down to 0.4) for precision (0.57 up to 0.67) on identical predictions. Once errors carry prices — a miss 5 times a false alarm — the comparison stops being a matter of taste: 8 versus 16, and the wide-net threshold wins by half.

Now Break It

Try this: Push the threshold to an extreme — catch everything (all positives) or nothing.

Control: Threshold slider (drag to either extreme)

What happens: Extreme threshold! At one end you flag everyone, at the other no one — both useless.

Where the decision threshold is used

The decision threshold is the cutoff that turns a model's continuous score or probability into a hard yes-or-no label, and choosing it is a business decision about consequences, not a mathematical default. Most libraries use 0.5 out of the box, but that value is rarely optimal and often actively wrong for imbalanced or cost-sensitive problems. A cancer screening tool might set a low threshold so it flags anyone with even moderate risk, accepting more false alarms to avoid missing a real case. A system that automatically blocks user accounts for suspected abuse might set a high threshold, acting only when very confident, because wrongly locking out a legitimate user is costly. The same trained model can serve very different needs simply by moving this cutoff.

The central misconception is that 0.5 is a principled, universal boundary rather than an arbitrary starting point. On imbalanced data, where the positive class is rare, the optimal threshold is frequently much lower, and picking it by hand ignores the actual costs of each error type. A better approach uses the precision-recall or ROC curve to select an operating point, or minimizes an explicit expected-cost objective that weights false positives and false negatives differently. One more caution: the threshold should be tuned on validation data and then evaluated on a separate untouched test set, because choosing the cutoff that maximizes a score on the same data you report on leaks information and inflates the result.

Frequently asked questions

Why is 0.5 not always the right decision threshold?
0.5 is just the default many tools use, not an optimal choice. On imbalanced data or when the two error types have different costs, a different cutoff usually performs better. The right threshold depends on how much a false positive costs relative to a false negative in your specific application.
How do I choose a good threshold?
Use the validation set to examine how precision, recall, and costs change across thresholds, often via a precision-recall or ROC curve, then pick the operating point that best matches your goals. When you can quantify the cost of each error type, choose the threshold that minimizes the expected total cost.
Does changing the threshold require retraining the model?
No. The threshold is applied after the model produces scores, so you can adjust it freely without retraining. This is convenient because one trained model can be tuned to different precision and recall tradeoffs simply by moving the cutoff.
Should I tune the threshold on the test set?
No. Selecting the threshold that maximizes a metric on the test set leaks information and gives an optimistic estimate. Tune the threshold on validation data, then report performance on a separate test set that was not used to make any choices.
How does the decision threshold relate to precision and recall?
Moving the threshold slides you along the precision-recall tradeoff. Lowering it labels more cases positive, raising recall but lowering precision, while raising it does the opposite. Choosing a threshold is really choosing where on that curve you want the model to operate.

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