Class imbalance: what oversampling amplifies
Oversampling raises weight, not information, and it multiplies the label noise inside the minority class by the same factor. Effective number of samples offers a gentler weighting that accounts for diminishing returns, but its parameter still has to be calibrated on your own validation set.
On this page
In an inspection dataset there are 200 defective samples and 20,000 normal ones; you copy the defects ten times to reach 2000 against 20000, and the training set looks balanced. Defect recall on validation climbs from 0.41 to 0.78, you ship, and two weeks later false positives have quadrupled. The problem is not copying as such. Copying does two things at once: it raises the weight of the class, and it raises the weight of every mislabelled sample inside it. Those two effects are entangled in the data, and you cannot scale one without the other.
The same image, ten times
Take the scene apart. Of those 200 defective samples, suppose six are mislabelled: a scratch filed as a dent, a reflection filed as a defect. Three percent, not high for human annotation. After copying ten times, those six become sixty. Their share of the training set is still three percent, but they now take part in ten times as many gradient updates.
The model does not know which copy is which. It sees this visual pattern sixty times, always labelled dent, and learns the mapping harder. Meanwhile the gradient from normal samples is diluted at every step, because the share of defective samples in a batch has gone from one percent to nine.
The net effect is that the model becomes more confident about the minority class, and part of that confidence rests on errors. The recall gain is real. The false-positive gain is real. Both come from the same action, and no threshold adjustment separates them, because they are not two ends of one axis.
What effective number of samples is after
The effective number of samples is one attempt to formalise this. It starts from an observation: as the number of samples grows, the benefit of an additional sample diminishes, because samples overlap, and the thousandth sample carries far less new information than the tenth.[1]
The paper gives each sample a small neighbouring region and defines the effective number of samples as the volume of those regions, which yields a closed form: one minus beta to the power n, divided by one minus beta, where n is the sample count and beta is a hyperparameter in the interval from zero up to but excluding one.[1]
Weights then go as the inverse of the effective number, not the inverse of the sample count.[1] The motivation targets the latter directly: weighting by inverse frequency assumes every additional sample brings equal new information, and that assumption fails once samples overlap.
One boundary has to be stated. This work is image classification, with experiments on artificially induced long-tailed CIFAR, ImageNet and iNaturalist.[1] The formula comes from a geometric intuition about overlapping neighbourhoods. Move it to text, instructions or dialogue and the neighbourhood becomes undefined: whether two sentences count as overlapping, and how close is close, has no standard answer. Borrow the idea, not the coefficients. That is my own practice, not the paper's claim.
Three classes, two weightings
Three classes with 5000, 500 and 50 samples. Take beta as 0.999, a value chosen here so the arithmetic is readable rather than a value the paper recommends. Compute the effective number, invert it, normalise, and compare with inverse-frequency weighting:
| Samples n | Effective number | Inverse effective | Normalised weight | Inverse-frequency weight |
|---|---|---|---|---|
| 5000 | 993 | 0.00101 | 1.00 | 1.00 |
| 500 | 393 | 0.00254 | 2.52 | 10.0 |
| 50 | 48.8 | 0.0205 | 20.3 | 100 |
The gap is immediate. Inverse frequency upweights the rarest class by 100; the effective number upweights it by 20. Nearly a factor of five. That difference is the over-correction: under inverse frequency, those 50 samples carry the gradient share of 5000, the model orbits them, and the mislabels inside them are amplified 100 times.
One more property gets missed. The effective number saturates quickly. The ratio between 5000 and 500 samples is 2.52 in effective terms against 10 in raw counts, so this accounting systematically compresses differences in data volume. That is good for long tails and bad for the intuition that more data means a stronger model: it says the five-thousandth sample is worth a fraction of the fiftieth.
Beta matters too. As beta approaches one, the effective number approaches the sample count and the weighting approaches inverse frequency; as beta falls, saturation arrives sooner and the weights flatten. On these same three classes, beta of 0.99 gives a weight ratio of roughly 1 to 1.01 to 2.53, far flatter than at 0.999. The paper treats beta as a hyperparameter, which means the sentence we applied class balancing carries almost no information. Without beta you do not know how far it balanced, or how many times it amplified the rarest class.
What gets amplified and what does not
| Object | After copying ten times |
|---|---|
| Weight of the minority class | Up tenfold. This is what you wanted |
| Label noise inside the minority class | Also up tenfold. This is the price |
| Surface features of the minority class (templates, lighting, wording, capture batch) | Amplified. The model treats this batch's signature as the class's signature |
| Genuine patterns that are representative | Amplified. Also wanted |
| New information | Not amplified. Copying produces none |
| Class prior | Changed. Output probabilities no longer match the real prior |
The last row deserves its own paragraph. Resampling changes the training distribution, and the model's output probabilities change with it: it overestimates the minority prior. If anything downstream uses a confidence threshold, inspection, risk scoring, screening, the threshold must be recalibrated. This is where many teams lose: metrics improve, deployment keeps the old threshold, and false positives spike. Nothing is wrong with the model; the scale was renumbered.
The third row is the quiet one. Minority samples often come from a handful of sources: one camera, one annotator, one collection batch. Copy ten times and the model learns not only what a defect looks like but that this camera's noise signature equals defect. Swap the device and performance falls off a cliff. You would not see it in validation, because validation came from the same batch.
Those two amplifications, noise and surface features, share one property: they are invisible on validation as long as validation is drawn from the same source. That is why metrics almost always improve after resampling, and why the improvement is not evidence of anything.
Five things to do before resampling
- Audit minority labels first. Minority classes are small, expensive to label and more often wrong. Reading those 200 samples beats copying them ten times.
- Prefer reweighting to resampling. Reweighting leaves the data intact, is reversible, and lets you sweep the parameter. Resampling is irreversible and moves the calibration.
- If you must duplicate, duplicate a cleaned subset and perturb the copies: crops, colour, noise for images; paraphrase and template changes for text. Otherwise you replicate the template, not the pattern.
- Keep validation at the original distribution. Measuring on the resampled distribution is awarding yourself the prize.
- Report per-class recall and precision plus a calibration curve, not overall accuracy or macro-F1 alone.
A note on the third step. The point of perturbation is not data augmentation for its own sake; it is to break the shortcut that identical pixels map to one label. With exact copies, reliance on that shortcut grows linearly in the copy count. Perturbation weakens the reliance without removing it, which is why step one still comes first: clean the labels before you multiply them.
One task for next week. Sort your training set by class size, take the smallest class, sample thirty items and check them by hand for a mislabel rate; do the same for thirty items of the largest class. If the minority rate is more than twice the majority rate, clean before you resample. Half a day of work, and it decides whether all your subsequent weighting amplifies signal or amplifies error.
