Why accuracy stops being a measurement
- : the share of the data that is positive.
On a dataset that is 1 percent positive, a model that always answers negative scores 99 percent, and it has learned nothing.
The loss has the same problem. Summed over the data, the 99 percent of easy negatives contribute almost all the gradient and the rare class barely moves the weights.
So imbalance is not a data problem that happens to hurt the metric. It is a weighting problem in the objective, and the repairs all change a weight somewhere.
Reweighting the loss
- : how many samples carry class .
- : the number of classes.
Weighting each class inversely to its frequency makes the rare class contribute as much total gradient as the common one, which is one line of code in every framework.
Focal loss reweights by difficulty instead of by class: an example the model already gets right has near 1, so its contribution is scaled to almost nothing.
With , an example predicted at 0.9 contributes a hundredth of what it would have. The gradient goes to what is still wrong.
Resampling, and what it costs
Random undersampling throws away majority rows. It is fast, it balances exactly, and it discards real data the model could have learned from.
Random oversampling duplicates minority rows. It keeps everything and gives the model the same few examples repeatedly, which is a direct invitation to memorise them.
SMOTE interpolates between a minority point and one of its minority neighbours, so the new points are new rather than copies.
It assumes the line between two minority points is also minority, which fails where the classes interleave, and it must be applied inside the cross-validation loop or it leaks.
Moving the threshold instead
A probability model does not have to be retrained at all. The default is a convention, not a result, and it is the wrong one under imbalance.
If a missed positive costs ten times a false alarm, the optimal threshold is about 0.09, and choosing it takes no training at all.
This is the first thing to try, because it is free, reversible, and it leaves the model calibrated.
One imbalanced problem, in order
- Check the base rate and pick a metric that does not reward the majority, such as PR-AUC or recall at a fixed precision.
- Train once with no correction at all, as the baseline everything else must beat.
- Add class weights, which cost nothing and usually capture most of the gain.
- Tune the decision threshold on a validation set against the real costs.
- Only then reach for resampling, and keep it strictly inside the cross-validation folds.