Undersampling

Also known as: random undersampling

On this page 7

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 ratioMajority examples keptShare of majority data retained
1:15,000About 0.5 percent
1:315,000About 1.5 percent
1:1050,000About 5 percent
No resampling995,000100 percent
Effect of target ratio on dataset size

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.

MethodSelection ruleTypical effect
Random undersamplingUniform random sample of majorityFast, may lose informative points
Tomek linksRemove majority point of cross-class nearest pairsCleans the class boundary
Edited nearest neighborsRemove points misclassified by their neighborsRemoves noise and overlap
NearMissKeep majority points closest to minority pointsFocuses on the boundary region
Cluster centroidsReplace majority clusters with k-means centroidsKeeps the overall data shape
Condensed nearest neighborKeep only points needed for 1-NN accuracyStrong reduction, sensitive to noise
Common undersampling methods

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.

StrategyMechanismMain advantageMain risk
UndersamplingRemove majority examplesSmaller, faster training setLoss of information
Random oversamplingDuplicate minority examplesNo data discardedOverfitting to duplicates
SMOTESynthesize minority points by interpolationRicher minority regionUnrealistic or noisy samples
Class weightsRaise loss for minority errorsUses all data unchangedRequires weight tuning
Threshold movingLower the decision thresholdNo retraining neededDoes not change learned features
Undersampling compared with alternative strategies

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.

SituationRecommended approachReason
Very large majority classRandom undersampling or ensemblesCuts training cost with little loss
Small dataset overallClass weights or SMOTEEvery example is valuable
Heavy class overlap or noiseTomek links or edited nearest neighborsCleans ambiguous boundary points
Calibrated probabilities requiredUndersampling plus recalibrationRestores true class priors
Decision guide for undersampling

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.