← All Posts
Deep Learning · Data Imbalance in Deep Learning · Class Imbalance and Resampling

SMOTE

SMOTE creates feature vectors between nearby examples of a selected class. Instead of repeating a minority row exactly, it chooses a minority neighbor and moves some fraction of the way toward it. The generated row receives that same class label.

The central assumption is geometric: points along that segment should make useful examples of the class. We will inspect one segment at a time, then examine when that assumption can fail.

Separate the choice of parents from the interpolation

01Choose a seedSelect an existing example from the class being expanded.
02Choose a class neighborFind its k nearest neighbors within that class, excluding itself. Choose one of those neighbors.
03Move along the segmentDraw a fraction between 0 and 1 and interpolate every coordinate using that same fraction.
One synthetic row in basic SMOTE. Repeat to generate the requested number of additional rows. The original training rows remain in the fitting dataset.

We describe basic SMOTE as implemented by imbalanced-learn. For a fixed neighborhood size, its generation step samples seed–neighbor pairs randomly. It does not allocate extra rows using a fitted classifier’s mistakes; ADASYN introduces a separate neighborhood-based allocation rule.

Write the equation after following one move

Let the seed be $x_i=(1,1)$ and its chosen neighbor be $x_j=(3,2)$. The displacement toward the neighbor is $x_j-x_i=(2,1)$. Moving one quarter of that displacement gives $(1,1)+0.25(2,1)=(1.5,1.25)$.

Writing the movement fraction as $\lambda$, the general interpolation is

$$x_{\mathrm{new}}=x_i+\lambda(x_j-x_i),\qquad 0\le\lambda\le1.$$

Use one fraction for the whole vector. Choosing a different fraction independently for each coordinate generally produces a point inside a box, not on the selected segment. At 0 the result is the seed; at 1 it is the neighbor.

Choose two parents, then move the synthetic point

A = (1, 1), B = (3, 2), C = (2, 5). With k = 2, either other minority point is an eligible neighbor.

012340123456Feature 1Feature 2ABC A → B at λ = 0.25: new point = (1.500, 1.250).
Solid dots are existing minority examples; the orange ring is the generated point. The slider includes both endpoints to illustrate the geometry. The library’s random fraction is drawn from [0, 1).

The distance calculation is a modeling choice

The neighbor search uses the class being expanded, not the whole dataset. A majority point can lie near or even on a selected segment without being used as a parent. Basic SMOTE does not check that the segment stays away from the other class.

Feature units affect which points are nearest. Fit a suitable scaling policy on the training data before the neighbor search. Also consider whether distance in this feature representation has useful meaning; scaling alone cannot establish that.

With $n_c$ rows in a class, an integer neighborhood size must satisfy $k<n_c$ to exclude the seed itself. The default k = 5 therefore needs at least six rows in that class in each training fold. Our three-point example deliberately uses k = 2. Duplicate coordinates can still give zero-length segments and repeated synthetic values.

Check whether the segment contains valid examples

Suppose two features encode a vector that must have length 1. The endpoints (1, 0) and (0, 1) are valid. Their midpoint (0.5, 0.5) has squared length 0.5, so it violates that constraint.

Two valid unit-length vectors are joined by a straight segment. Their midpoint at one half, one half lies inside the unit circle and does not have unit length.
Linear interpolation follows the chord. The valid feature combinations follow a curve. Valid parents are not sufficient evidence that every point between them is valid.

Other examples include categorical codes, integer counts and coupled physical measurements. Interpolating one-hot category vectors can produce fractions that do not represent a category. For mixed numeric and categorical data, consider SMOTENC; for entirely categorical data, SMOTEN uses a different generation procedure.

Large neighborhoods can connect distinct minority groups through a majority region. Sparse minority data or mislabeled seeds can also generate misleading points. Inspect representative parent pairs and generated examples, and compare with exact oversampling, weighting and no resampling. More synthetic rows do not provide more independent labels.

Fit the geometry and sampler inside training

Split original observations first. Inside each training fold, fit any imputation and scaling, apply SMOTE, then fit the classifier. Evaluate the fitted pipeline on original validation observations. Never generate synthetic neighbors using validation or test rows.

Scaling before SMOTE learns a different neighbor geometry from an unscaled feature space. Choose the scaling, $k$ and sampling target through validation, checking the minority count in each fold. The sampler is bypassed during prediction; it does not alter the validation population.

References and further reading