Decision Thresholds and Cost-Sensitive Learning
A model gives you a probability; a threshold turns that probability into an action. Where you put the cutoff should be decided by what mistakes cost you, not by the 0.5 that every library hands you as a default.
Prerequisites: The Confusion Matrix and Classification Metrics, Probability Calibration, Expected Value
Your model looks at a transaction and returns 0.31. Now what? The number is not a decision. Somebody has to say whether 0.31 is high enough to block the card, and nothing inside the model answers that. In practice almost nobody decides — they call .predict(), the library silently compares against 0.5, and a business-critical choice gets made by a default argument.
That default is only correct in one situation: when being wrong in one direction costs exactly as much as being wrong in the other. Almost nothing in finance looks like that. Missing a fraudulent charge costs hundreds of dollars; wrongly flagging a good one costs a few minutes of an analyst's time. Any cutoff that treats those two as equal is throwing money away, and no amount of extra model training will fix it, because the problem is not in the model.
The analogy: the sensitivity dial on a smoke alarm
A smoke alarm has a detector and a dial. The detector measures particles in the air — that part is physics, and it is the same in every room. The dial sets how many particles trigger the siren.
In a kitchen you turn the dial down, because burnt toast waking the house is annoying but a missed fire is catastrophic. In a recording studio you might turn it up, because a false siren ruins a take. Same detector, same physics, different dial — because the consequences differ, not the smoke.
A classifier's probability output is the detector. The threshold is the dial. Retraining the model improves the detector. Choosing the threshold sets the dial. They are separate jobs and they are solved with separate information: the model is fitted from data, the threshold is chosen from costs.
The rule, in one line
Write for the model's estimated probability that the positive class is true — say, that this transaction is fraud. Write for the cost of a false positive (you acted, and you should not have) and for the cost of a false negative (you did nothing, and you should have acted).
If you act, you pay whenever the case turns out negative, which happens with probability . If you do not act, you pay whenever it turns out positive, which happens with probability . Acting is worth it exactly when its expected cost is smaller:
In words: the right cutoff is the false-alarm cost expressed as a share of the total cost of the two mistakes. If a false alarm is cheap relative to a miss, sits near zero and you act on flimsy evidence. If the two cost the same, and the fraction is exactly — which is where the library default comes from, and it is a claim about your costs, not a neutral position.
Worked example 1: card fraud, counted out
A bank scores 100,000 transactions. 300 of them are genuinely fraudulent — 0.3%. A missed fraud costs $400 in write-off and chargeback fees. A false flag costs $12 in analyst review and customer irritation.
Step 1 — the threshold. . Act on anything above about 2.9%.
Step 2 — cost at the default cutoff of 0.5. At that height the model catches 120 frauds, misses 180, and raises 30 false flags.
Step 3 — cost at . Lowering the bar catches 255 frauds, misses 45, and raises 2,600 false flags.
That is $23,160 saved on 100,000 transactions, from changing one number. Now look at what happened to accuracy. At 0.5 the model got cases right, or 99.79%. At it got right, or 97.36%. Accuracy fell by 2.4 points while cost fell by a third. Accuracy is a scoreboard that prices every mistake at one dollar; your business does not.
Worked example 2: the same threshold logic on a trading signal
A model outputs , the probability that a name rises over the next hour. The payoffs are not a cost matrix; they are a P&L. Enter the trade only if expected P&L clears the round-trip cost:
where is the gain when you are right, the loss when you are wrong, and the round-trip transaction cost.
Case A — symmetric payoff. bp, bp, bp. Then , so and . Costs alone push the bar 11 points above the coin-flip line.
Case B — skewed payoff. Same model, but the trade is structured so a win pays bp and a loss caps at bp, with the same bp. Then , so and .
Now take a signal that fires at and check both by hand. Under Case A the expected P&L is bp — a losing trade. Under Case B it is bp — a good one. Identical model, identical probability, opposite decisions, because the payoff geometry moved the threshold from 0.611 to 0.40.
Cost-sensitive learning: the other way to the same place
There are two ways to make a model care about asymmetric costs.
Move the threshold after training. Fit normally, then set from the cost ratio. Cheap, transparent, reversible.
Weight the training loss. Multiply the loss on positive examples by a factor so the optimiser tries harder not to miss them. For a well-calibrated model the two are the same thing. If you upweight positives by , the model's reported probability relates to the honest probability by , and thresholding at 0.5 means
Check it against example 1. The cost ratio there was , so gives a threshold of — the same 2.9% cutoff you got from the cost formula directly. The two roads meet.
The explorer below draws a logistic curve; drag its steepness and watch how many points sit close to any horizontal cutoff line. A flat curve means the threshold choice moves a huge number of cases, so it matters enormously. A steep one means most cases are far from any plausible cutoff and the threshold barely matters.
The optimal cutoff is — the false-alarm cost as a share of total error cost. Using 0.5 is not neutral; it is an assertion that your two mistakes cost the same.
What this means in practice
The threshold is free alpha, and it is usually left on the table. Retraining to squeeze out another point of AUC is expensive. Recomputing a cutoff from a cost ratio takes an afternoon and often moves more money.
Calibration is a prerequisite, not a nicety. The formula reads the model's output as a real probability. If a gradient-boosted model's "0.03" actually means 8% in the wild, is being applied to a number that does not mean what the derivation assumed. Calibrate first, threshold second.
Costs drift. Analyst headcount changes, chargeback fees get renegotiated, execution costs fall. The threshold should be a configuration value that someone owns and revisits, not a constant compiled into a model artefact.
Tune it on validation data, report it on test data. Sweeping thresholds on the same set you quote results from is just Data-Snooping Bias wearing a different hat.
Moving the threshold does not make the model better. It slides you along a fixed ROC curve, trading recall for precision; the curve itself only moves when the model changes. Three traps follow. First, people report a threshold improvement as a modelling improvement — it is not. Second, if you both class-weight during training and shift the threshold afterwards, you have applied the same correction twice and pushed past the optimum. Third, class imbalance by itself is not a reason to resample or reweight — imbalance changes the base rate, which the model should learn honestly, while the costs are what should change your cutoff. Fix the decision rule, not the data.
Practise it
- A model flags loan defaults. A missed default costs $9,000; a wrongly declined good applicant costs $150 in lost margin. What is ? (Answer: .)
- Your risk team says false positives now cost $300 instead of $12 in example 1, because each flag freezes a customer account. Recompute and decide whether the default 0.5 is now closer to right. (Answer: — much closer, but still below 0.5.)
- In example 2 Case A, what does the round-trip cost have to fall to before a signal becomes profitable? (Answer: bp.)
- Take any model you have trained. Plot total cost against threshold using your real cost numbers and mark where 0.5 sits. If the curve is flat there, the default was harmless; if it is on a steep flank, you have been leaving money behind.
Related concepts
Practice in interviews
Further reading
- Elkan, The Foundations of Cost-Sensitive Learning (2001)
- Hastie, Tibshirani & Friedman, The Elements of Statistical Learning, ch. 9.2