🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Machine Learning Notes
Topic #212

SMOTE

SMOTE (Synthetic Minority Oversampling Technique) fixes plain oversampling's biggest weakness — instead of duplicating existing minority points exactly, it generates new, synthetic minority examples by interpolating between real ones.

The Algorithm

StepWhat Happens
1Pick a random minority-class point \(x_i\)
2Find its \(k\) nearest minority-class neighbors (typically \(k=5\))
3Randomly pick one neighbor, \(x_{zi}\)
4Generate a new synthetic point along the line segment between them
5Repeat until the desired class balance is reached

Formula

\[ x_{\text{new}} = x_i + \lambda(x_{zi}-x_i), \qquad \lambda \sim \text{Uniform}(0,1) \]

\(\lambda\) is a random number between 0 and 1, so the new synthetic point lands somewhere along the straight line connecting \(x_i\) and its neighbor — never exactly on top of either one.

Worked Example

Minority point \(x_i=(2,3)\), its nearest minority neighbor \(x_{zi}=(4,5)\), random \(\lambda=0.5\):

\[ x_{\text{new}} = (2,3) + 0.5\bigl((4,5)-(2,3)\bigr) = (2,3)+0.5(2,2) = (3,4) \]

The synthetic point \((3,4)\) sits exactly halfway between the two real minority points — a genuinely new example, not a duplicate of either.

Graphical Intuition

x_i (2,3) x_zi (4,5) synthetic (3,4)

The new point is a plausible interpolation between two real minority examples — not an exact copy of either one.

Python Implementation

from imblearn.over_sampling import SMOTE
from collections import Counter

smote = SMOTE(k_neighbors=5, random_state=42)
X_resampled, y_resampled = smote.fit_resample(X_train, y_train)

print(Counter(y_train))        # {0: 950, 1: 50}
print(Counter(y_resampled))     # {0: 950, 1: 950} -- balanced with SYNTHETIC, not duplicated, minority points

SMOTE vs Plain Oversampling

Plain OversamplingSMOTE
New minority pointsExact duplicatesSynthetic, interpolated points
Overfitting to specific points?Higher riskLower risk
Requires numeric featuresNo — works on anythingYes — interpolation needs continuous numeric features

Practical Use Cases

  • The most commonly used resampling technique for imbalanced tabular classification with numeric features
  • Fraud, medical, and defect-detection datasets where minority examples are genuinely scarce

Limitations

  • Only works cleanly on numeric features — categorical features need a variant like SMOTE-NC
  • Can generate synthetic points in ambiguous or noisy regions if minority-class examples are themselves scattered and not well-clustered
  • Must still only ever be applied to the training set, same as any resampling technique

Common Mistakes

  • Applying vanilla SMOTE to data with categorical features without switching to SMOTENC or a similar variant.
  • Using a \(k\) for nearest neighbors larger than the number of available minority samples — SMOTE needs at least \(k+1\) minority examples to work.

Interview Relevance

Q: "Why is SMOTE generally preferred over simple random oversampling?" Random oversampling duplicates existing minority points exactly, which can cause a model to overfit to those specific repeated examples; SMOTE instead generates new, synthetic points by interpolating between real minority examples, giving the model more varied, plausible minority-class data to learn from.

Practice Question

Given minority points \(x_i=(1,1)\) and its neighbor \(x_{zi}=(5,9)\), compute the synthetic point SMOTE would generate with \(\lambda=0.25\).

Want to go beyond the notes?

Join CodingNow 2.0's Machine Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

SMOTE – FAQs

Quick answers about learning SMOTE in Machine Learning.

This free note from CodingNow 2.0 explains SMOTE in Machine Learning — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Machine Learning topic on CodingNow 2.0, including SMOTE, is 100% free with no signup required.
With focused practice, most students grasp SMOTE in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now