The idea
With a 1% positive rate, the model can be 99% accurate by doing nothing. Imbalance breaks the silent assumptions of default classification — that 0.5 is a sensible threshold, that accuracy measures usefulness, and that both error types cost the same. The fixes live at three layers:
1. The metric layer. Accuracy → precision/recall and PR curves. The mechanical reason ROC flatters: FPR has the giant negative class in its denominator, so an avalanche of false alarms barely dents it, while precision takes the hit in full. Judge PR-AUC against its no-skill baseline — the prevalence, not 0.5. Use stratified CV so folds contain positives at all.
2. The training layer. Make rare examples matter:
- Class weights — count each minority example times in the loss (typically inverse frequency). Same effect as oversampling, no duplication, one line in most libraries.
- Random over/undersampling — duplicate minority rows or discard majority rows. Undersampling can waste data; oversampling can overfit duplicated points.
- SMOTE — synthesize minority points by interpolating between minority neighbors. Helps sometimes on tabular data; hurts when classes overlap (it fabricates positives inside majority territory). And it must run inside the CV fold — SMOTE before the split leaks and inflates scores, the single most common imbalance bug.
3. The decision layer — usually the right one. Imbalance is really a cost asymmetry problem. With calibrated probability , a missed-positive cost , and a false-alarm cost that applies only when the case is actually negative, flag when expected cost says so:
If taking the action has a fixed cost for every flagged case (such as a manual review), compare directly with : flag when .
The 0.5 default corresponds to equal costs — almost never true when one class is rare. A well-ranked, well-calibrated model plus the right threshold often beats any resampling scheme, and it keeps probabilities honest for downstream use. Caveat for rebalancers: training on altered prevalence distorts the posterior — recalibrate on true-prevalence data or apply the known prior correction.
Move one decision threshold. The model scores stay fixed; every metric and cost changes around that choice.
Cost assumes $10 per false alarm and $500 per miss. Lower thresholds catch more positives; prevalence determines how many false alarms surround them.
Worked example
Fraud detection: transactions, prevalence 1% → 100 fraud, 9,900 legitimate. Model operates at TPR , FPR :
On the ROC plot, (FPR 0.05, TPR 0.80) looks like a strong classifier. In the queue a human reviews, 6 of every 7 alerts are false — the ROC point and the analyst experience are describing the same model.
Now the cost view. A missed fraud costs $500; every manual review costs $10:
Flag anything with fraud probability above 2% — twenty-five times more aggressive than the 0.5 default. Sanity-check with expected cost at this operating point: the current confusion matrix costs dollars per 10k transactions. A blanket-review policy would cost dollars; doing nothing costs dollars. The model earns its keep only through where you put the threshold — and 0.5 was never a candidate.
Cheat sheet
Cost-optimal threshold (calibrated ): with a false-alarm-only cost, flag when ; with a fixed action/review cost on every alert, flag when . Equal false-positive/false-negative costs → 0.5; rare-and-costly misses → tiny threshold.
PR vs ROC: rare positives + flagging workload ⇒ PR (baseline = prevalence). Balanced classes / prevalence-free comparison ⇒ ROC (baseline 0.5).
| Tool | What it does | Watch out |
|---|---|---|
| Threshold tuning | moves operating point, model untouched | needs calibrated or at least monotone scores |
| Class weights | reweights loss toward minority | distorts calibration; recalibrate after |
| Random oversampling | duplicates minority rows | overfits duplicates |
| Random undersampling | drops majority rows | discards signal; try ensembles of undersamples |
| SMOTE | interpolates synthetic minority points | leaks if before split; fabricates points in overlap regions |
| Cost-sensitive learning | bakes into training | requires actually knowing the costs |
- Fit resampling INSIDE the CV fold; evaluate ALWAYS on untouched, true-prevalence data.
- No-skill precision = prevalence; quote PR-AUC relative to it.
- Rebalanced training ⇒ probabilities biased toward minority; fix via calibration on true-prevalence data or logit shift by .
- Stratify CV folds; never let a fold go positive-free.
- Alert-budget framing: capacity of reviews/day ⇒ optimize precision@k / recall@k, not a global scalar.
- First question to ask: are the negatives clean, or just undetected positives? Label noise masquerades as imbalance.