SMOTE (Synthetic Minority Over-sampling Technique)

SMOTE builds new minority-class rows instead of copying existing ones. For a minority point \(x\), it picks one of that point’s \(k\) nearest minority neighbors \(x_{nn}\) and places a synthetic point somewhere on the segment between them:

\[ x_{new} = x + \delta \cdot (x_{nn} - x), \qquad \delta \sim U(0,1) \]

Chawla and colleagues introduced it in 2002, and the paper is worth reading for what it actually claimed: the method evaluated there was oversampling the minority combined with undersampling the majority, and it was judged in ROC space rather than by accuracy. Both details matter, and both are usually dropped when SMOTE is described as a drop-in fix for imbalance.

What it moves, and what it breaks

import numpy as np
from imblearn.over_sampling import SMOTE
from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_auc_score, brier_score_loss, recall_score, precision_score
from sklearn.model_selection import train_test_split

X, y = make_classification(n_samples=20000, n_features=8, n_informative=5,
                           weights=[0.98], flip_y=0.01, random_state=0)
xtr, xte, ytr, yte = train_test_split(X, y, test_size=0.3, stratify=y, random_state=0)
xs, ys = SMOTE(random_state=0).fit_resample(xtr, ytr)
"""The sampler is fitted on the training part only; the test set stays at its natural rate."""

plain = LogisticRegression(max_iter=5000).fit(xtr, ytr)
smote = LogisticRegression(max_iter=5000).fit(xs, ys)
for name, m in (("no resampling", plain), ("SMOTE", smote)):
    p = m.predict_proba(xte)[:, 1]
    print(f"{name:<14} AUROC {roc_auc_score(yte, p):.4f}  Brier {brier_score_loss(yte, p):.5f}"
          f"  mean predicted risk {p.mean():.4f}"
          f"  recall@0.5 {recall_score(yte, p >= 0.5):.4f}  precision@0.5 {precision_score(yte, p >= 0.5):.4f}")
print(f"actual event rate in the test set {yte.mean():.4f}")

pp = plain.predict_proba(xte)[:, 1]
# Post-hoc diagnostic on this test set, not an independent policy evaluation.
# For deployment, choose the threshold on validation data, then evaluate on a separate test set.
target = recall_score(yte, smote.predict_proba(xte)[:, 1] >= 0.5)
th = min(np.unique(pp), key=lambda t: abs(recall_score(yte, pp >= t) - target))
print(f"no resampling, threshold moved to {th:.4f}: recall {recall_score(yte, pp >= th):.4f}"
      f"  precision {precision_score(yte, pp >= th):.4f}")
# no resampling  AUROC 0.8876  Brier 0.01231  mean predicted risk 0.0240  recall@0.5 0.4392  precision@0.5 0.9420
# SMOTE          AUROC 0.8997  Brier 0.09985  mean predicted risk 0.2572  recall@0.5 0.8311  precision@0.5 0.1425
# actual event rate in the test set 0.0247
# no resampling, threshold moved to 0.0176: recall 0.8311  precision 0.0978

Read the columns separately, because they tell different stories.

Discrimination improves slightly in this run: AUROC rises from 0.8876 to 0.8997. Interpolation creates additional training points under an assumption of local minority-class plausibility. Gaussian class distributions can overlap, however, so a point between two minority observations is not guaranteed to belong to that class. Validate the effect instead of inferring label correctness from the generator.

The probabilities broke. The true event rate is 0.0247. Without resampling the model’s average predicted risk is 0.0240; after SMOTE it is 0.2572, and the Brier score is eight times worse. This is not a subtlety โ€” the model was fitted on a 50/50 population, so it estimates risk in a world that does not exist. Decisions that consume these probabilities as risks can be distorted; evaluate calibration and decision costs on the target population.

The headline gain is a threshold move. Recall at 0.5 rises from 0.4392 to 0.8311, which is the number usually quoted. But precision falls from 0.9420 to 0.1425, and the last line shows the original model reaching the same recall simply by using 0.0176 as its cut-off. In this run SMOTE’s precision at that operating point is better โ€” 0.1425 against 0.0978 โ€” which is the +0.012 of AUROC showing up where it matters. The matched-recall calculation is a post-hoc diagnostic on this test set: it selects a cutoff using these same labels, so it is not an independent estimate of a deployable policy. For a policy comparison, choose the cutoff on validation data and evaluate the fixed rule on a separate test set. Comparing operating points separates threshold effects from changes to the scorer.

Van den Goorbergh and colleagues found the same pattern across simulated and clinical data: imbalance corrections produced strongly overestimated minority probabilities, no better area under the ROC curve, and sensitivity changes that were reproducible by shifting the threshold.

Where the synthetic points land

SMOTE can interpolate through majority territory when neighbors cross a gap, but that is not its only failure mode. Overlap, label noise and a curved or nonconvex minority support can make even the nearest-neighbor segment implausible.

import numpy as np
from imblearn.over_sampling import SMOTE
from sklearn.model_selection import train_test_split

rng = np.random.default_rng(0)
majority = rng.normal(0, 1.0, size=(9800, 2))
minority = np.vstack([rng.normal([-3.0, 0], 0.35, size=(100, 2)),
                      rng.normal([3.0, 0], 0.35, size=(100, 2))])
"""The minority class sits in two pockets with an empty corridor between them,
   and the majority class fills that corridor."""
X = np.vstack([majority, minority])
y = np.r_[np.zeros(9800, int), np.ones(200, int)]
xtr, _, ytr, _ = train_test_split(X, y, test_size=0.3, stratify=y, random_state=0)
print(f"minority rows available for interpolation: {int(ytr.sum())} (about {int(ytr.sum())//2} per pocket)")

for k in (5, 20, 50, 100, int(ytr.sum()) - 1):
    xs, _ = SMOTE(random_state=0, k_neighbors=k).fit_resample(xtr, ytr)
    new = xs[len(xtr):]
    landed = int((np.abs(new[:, 0]) < 1.5).sum())
    print(f"k_neighbors {k:4d}  synthetic points {len(new)}  landing in the empty corridor {landed:5d} ({landed / len(new):.1%})")
# minority rows available for interpolation: 140 (about 70 per pocket)
# k_neighbors    5  synthetic points 6720  landing in the empty corridor     0 (0.0%)
# k_neighbors   20  synthetic points 6720  landing in the empty corridor     0 (0.0%)
# k_neighbors   50  synthetic points 6720  landing in the empty corridor     0 (0.0%)
# k_neighbors  100  synthetic points 6720  landing in the empty corridor  1140 (17.0%)
# k_neighbors  139  synthetic points 6720  landing in the empty corridor  1646 (24.5%)

With roughly 70 minority rows in each pocket, every neighbor list of size 5, 20 or 50 stays inside one pocket, and not a single synthetic point falls in the corridor. At \(k = 100\) the list has to cross, and 17% of the new rows land in the empty space that belongs to the majority class. At \(k = 139\) โ€” every other minority row is a candidate โ€” it is nearly a quarter.

In this two-pocket construction, increasing k beyond a pocket’s size makes cross-pocket interpolation possible. The default k=5 avoids that particular corridor here; it is not a general safety guarantee. Inspect the geometry and neighbor purity and compare suitable variants or cleaning steps through validation. A smaller k cannot repair every overlap or mislabeled seed.

Two conditions that break it outright

  • Categorical features. Interpolating halfway between “Tuesday” and “Friday”, or between two one-hot columns, produces a row that cannot occur. imbalanced-learn provides SMOTENC for mixed data and SMOTEN for all-categorical data, which take the majority category among neighbors instead of averaging.
  • Resampling before the split. A synthetic row is built from real rows; if those originals end up in the test set, the model has seen the answer. imbalanced-learn documents this as its main pitfall, and the fix is the same as for any preprocessing step โ€” fit the sampler inside each cross-validation fold and evaluate on data left at its natural rate. It is ordinary leakage, and it grows with the sampling ratio.

Deciding whether to use it

Ask what the model’s output feeds. If a probability is consumed downstream, SMOTE costs you calibration and you will need to recalibrate against data at the natural rate. If a ranking is consumed, compare against the unresampled model at a matched operating point โ€” that comparison is cheap and it is the only one that separates the method from the threshold.

And if the minority class is small in absolute terms rather than merely rare โ€” a few dozen rows โ€” the honest constraint is that there is little to interpolate between. Imbalance and data scarcity are different problems, and synthesis only addresses the first.

References


Discover more from Insightful Data Lab

Subscribe to get the latest posts sent to your email.

Similar Posts

Questions, corrections, or additional insights?

This site uses Akismet to reduce spam. Learn how your comment data is processed.