Home Knowledge Base Undersampling

Undersampling is a technique for handling imbalanced datasets by reducing the number of majority class examples — rather than creating more minority examples (oversampling), undersampling removes majority examples until the classes are balanced, trading dataset size for class balance, which is fast and simple but risks discarding valuable information from the majority class that the model could have learned from.

What Is Undersampling?

Undersampling Methods

MethodApproachProsCons
Random UndersamplingRandomly select N majority examples (N = minority count)Simplest, fastestMay discard important edge cases
Tomek LinksRemove majority examples that form "Tomek Links" with minority examples (nearest neighbors of opposite class)Only removes ambiguous boundary examplesMild reduction, may not fully balance
Edited Nearest Neighbors (ENN)Remove majority examples whose nearest neighbors are mostly minorityCleans noisy boundary regionsConservative, small reduction
NearMissKeep majority examples closest to minority examplesPreserves boundary-relevant examplesCan lose global majority patterns
Cluster CentroidsReplace majority class with cluster centroids using K-MeansPreserves distribution structureGenerated centroids may not be realistic
One-Sided Selection (OSS)Remove Tomek links + redundant majority examplesBalanced approachMore complex

Example: Random Undersampling

BeforeAfter
Class A (Legitimate): 10,000Class A: 100 (randomly selected)
Class B (Fraud): 100Class B: 100 (unchanged)
Total: 10,100Total: 200
Ratio: 100:1Ratio: 1:1

Tomek Links (Smart Undersampling)

A Tomek Link is a pair of examples (one from each class) that are each other's nearest neighbor. These pairs sit right on the decision boundary and are the most ambiguous examples. Removing the majority example from each Tomek Link cleans the boundary without aggressive data removal.

Python Implementation

from imblearn.under_sampling import (
    RandomUnderSampler, TomekLinks, EditedNearestNeighbours
)

# Random undersampling
rus = RandomUnderSampler(random_state=42)
X_resampled, y_resampled = rus.fit_resample(X_train, y_train)

# Tomek Links (smart boundary cleaning)
tl = TomekLinks()
X_clean, y_clean = tl.fit_resample(X_train, y_train)

Undersampling vs Oversampling

FactorUndersamplingOversampling (SMOTE)
Dataset size afterSmaller (faster training)Larger (slower training)
InformationLoses majority examplesKeeps all original + adds synthetic
RiskUnderfitting (too little data)Overfitting (synthetic noise)
SpeedFastModerate
Best whenMajority class is very large (millions)Dataset is small overall

Undersampling is the fast, simple approach to class imbalance — trading majority class examples for balanced class distributions, best used when the majority class is large enough that removing examples doesn't sacrifice important patterns, with Tomek Links and Edited Nearest Neighbors providing smarter alternatives to random removal by targeting only the ambiguous boundary examples.

undersamplingbalancereduce

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.