Oversampling#
Rebalancing classes by replicating or synthesising additional minority-class examples.
Important
✨ AI-generated content. This page was written with the assistance of an AI language model and is provided as a learning aid. Despite careful review, it may still contain mistakes, omissions, or out-of-date information. Whether you are new to the topic, a team lead, or a senior practitioner, treat it as a starting point rather than an authoritative reference: read it critically and independently verify anything you act on (code, commands, figures, and factual claims) against official documentation and primary sources before relying on it.
What it is#
Oversampling is a resampling strategy for class imbalance that grows the minority class — by duplicating real samples or generating new ones — until the classes are closer to balanced. It is the mirror image of undersampling, which shrinks the majority class instead.
Why it’s used#
When one class is rare (fraud, disease, defects), a model can reach high accuracy by almost always predicting the majority class while essentially ignoring the minority. Oversampling raises the minority’s presence in training so the model is forced to learn it, usually improving minority-class recall and F1.
How it’s done#
Random oversampling — duplicate existing minority rows at random until the counts match.
Synthetic oversampling — create new minority points with methods such as SMOTE or ADASYN instead of exact copies.
Trade-offs#
Advantages:
Stops the model from ignoring the minority class.
Random oversampling is trivial to apply.
Often lifts recall and F1 for the rare class.
Disadvantages:
Duplicating rows can cause overfitting to those exact points.
A larger training set means longer training.
Synthetic methods can introduce unrealistic or noisy samples.
Example#
With 10,000 non-fraud and 1,000 fraud rows, oversampling brings the fraud class up to 10,000 — by duplication (random) or by synthesis (SMOTE).
from collections import Counter
from imblearn.over_sampling import RandomOverSampler, SMOTE
X_dup, y_dup = RandomOverSampler(random_state=42).fit_resample(X, y)
X_syn, y_syn = SMOTE(random_state=42).fit_resample(X, y)
print(Counter(y_dup), Counter(y_syn))
Theme: Imbalanced Learning & Resampling · All terminology
Hint
Mind map — connected ideas
SMOTE (Synthetic Minority Over-sampling Technique) · Random Undersampling · Class Weighting · Subsampling · Cluster-based undersampling
Hint
More in Imbalanced Learning & Resampling
Class Weighting · Cluster-based undersampling · Downsampling · NearMiss (Distance-based Undersampling) · Random Undersampling · SMOTE (Synthetic Minority Over-sampling Technique) · Subsampling · Upsampling
See also
Source article Adapted (context, re-expressed) in our own words from: Oversampling (insightful-data-lab.com).