Undersampling is a data-level technique for class imbalance that reduces the number of majority-class examples in a training set so that the classes are closer to equal size. In machine learning, it is one of the simplest ways to stop a classifier from ignoring a rare class such as fraud, defects or disease, and in its basic form it is called random undersampling.
The method trades information for balance. Discarding examples makes training faster and shifts the decision boundary toward the minority class, but it can also remove useful patterns, so practitioners in artificial intelligence choose the variant, the target ratio and the evaluation metric with care.
How undersampling changes the training data
Undersampling works by selecting a subset of the majority class and keeping every minority example. When fraud makes up 0.5 percent of 1,000,000 transactions, a learner that predicts every case as legitimate already reaches 99.5 percent accuracy, so the loss function gives it almost no reason to detect fraud. Removing most legitimate cases changes that incentive.
The key parameter is the sampling ratio, the target proportion of minority to majority examples after resampling. A ratio of 1:1 gives full balance, while milder ratios such as 1:3 or 1:5 often keep more information and perform better. The ratio is a hyperparameter to tune on validation data, not a fixed rule.
The table below illustrates how different target ratios affect a dataset with 5,000 minority and 995,000 majority examples.
| Target ratio | Majority examples kept | Share of majority data retained |
|---|---|---|
| 1:1 | 5,000 | About 0.5 percent |
| 1:3 | 15,000 | About 1.5 percent |
| 1:10 | 50,000 | About 5 percent |
| No resampling | 995,000 | 100 percent |
Random and informed undersampling methods
Undersampling methods differ in which majority examples they remove. Random undersampling draws a uniform sample without regard to position in feature space, while informed methods use nearest-neighbor rules or clustering to delete redundant, noisy or borderline points.
| Method | Selection rule | Typical effect |
|---|---|---|
| Random undersampling | Uniform random sample of majority | Fast, may lose informative points |
| Tomek links | Remove majority point of cross-class nearest pairs | Cleans the class boundary |
| Edited nearest neighbors | Remove points misclassified by their neighbors | Removes noise and overlap |
| NearMiss | Keep majority points closest to minority points | Focuses on the boundary region |
| Cluster centroids | Replace majority clusters with k-means centroids | Keeps the overall data shape |
| Condensed nearest neighbor | Keep only points needed for 1-NN accuracy | Strong reduction, sensitive to noise |
Cleaning methods such as Tomek links and edited nearest neighbors rarely reach full balance on their own, so they are often combined with random undersampling or with SMOTE, as in the SMOTE-Tomek and SMOTE-ENN pipelines.
Undersampling compared with other imbalance strategies
Undersampling is one of three broad responses to class imbalance, alongside oversampling and cost-sensitive learning. Each changes what the model sees or how it is penalized, and each has a characteristic weakness.
| Strategy | Mechanism | Main advantage | Main risk |
|---|---|---|---|
| Undersampling | Remove majority examples | Smaller, faster training set | Loss of information |
| Random oversampling | Duplicate minority examples | No data discarded | Overfitting to duplicates |
| SMOTE | Synthesize minority points by interpolation | Richer minority region | Unrealistic or noisy samples |
| Class weights | Raise loss for minority errors | Uses all data unchanged | Requires weight tuning |
| Threshold moving | Lower the decision threshold | No retraining needed | Does not change learned features |
Ensemble methods reduce the information loss of undersampling. EasyEnsemble and balanced random forest train many models, each on a different balanced subsample, so that together they still see most of the majority data.
Applying undersampling correctly
Undersampling must be applied only to the training folds. Resampling before the train-test split, or across all folds of cross-validation, causes data leakage and produces test scores that do not reflect real class frequencies.
Because resampling changes class priors, the predicted probabilities become biased toward the minority class. When calibrated probabilities matter, for example in credit risk or medical triage, practitioners apply a prior correction or recalibrate on untouched validation data.
| Situation | Recommended approach | Reason |
|---|---|---|
| Very large majority class | Random undersampling or ensembles | Cuts training cost with little loss |
| Small dataset overall | Class weights or SMOTE | Every example is valuable |
| Heavy class overlap or noise | Tomek links or edited nearest neighbors | Cleans ambiguous boundary points |
| Calibrated probabilities required | Undersampling plus recalibration | Restores true class priors |
Limitations and evaluation pitfalls
The central limitation is information loss: removed examples may contain rare subtypes of the majority class, which raises the false positive rate after deployment. Results also vary between random draws, so reports should average several seeds.
- Accuracy is misleading on imbalanced data; use recall, precision, F1 score or precision-recall AUC.
- Evaluating on a resampled test set hides the real false positive burden.
- Over-aggressive ratios can make the model flag too many normal cases.
- Strong learners such as gradient boosting sometimes gain little from resampling compared with class weights.
Explained without jargon
Imagine teaching someone to spot counterfeit coins. You show them 1,000 real coins and only 5 fakes. They may learn to call every coin real, because that is almost always right. Undersampling fixes this. It sets aside most of the real coins so the learner sees a fairer mix of both kinds.
The learner now notices what makes a fake different. The cost is that some useful real coins go unused. That is why careful teams test different mixes and check results on data that looks like the real world.
A typical use case
A manufacturer inspects circuit boards with sensors and records 2.4 million readings, of which only 3,600 belong to defective boards. A gradient boosting model trained on the raw data reaches high accuracy but catches only 41 percent of defects, because the rare class barely affects the loss.
The data science team applies random undersampling at a 1:5 ratio inside each training fold, keeping every defect and 18,000 normal readings, and trains an ensemble of ten models on different subsamples. On an untouched test set with the original class balance, defect recall rises to 83 percent while precision stays acceptable for the inspection line. Training time drops from hours to minutes, and the team recalibrates the scores so that the reported defect probability matches observed rates.