0Pricing
Data Science Academy · Lesson

Resampling: SMOTE and Undersampling

Rebalancing the training set.

Resampling: SMOTE and Undersampling is a free Data Science Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Data Science Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Rebalance the Training Set

One way to help a model see the rare class is to resample: change how many examples of each class it trains on.

Two Directions to Balance

You can add more of the minority (oversample) or trim the majority (undersample). Both aim to even out the class counts.

Naive Oversampling

The simplest oversample just copies minority rows until counts match. It works, but those exact duplicates can make a model memorize them.

Enter SMOTE

SMOTE creates synthetic minority examples instead of copies. It invents new, plausible points between real minority neighbors.

How SMOTE Builds Points

SMOTE picks a minority row, finds a nearby minority neighbor, and places a fresh point somewhere on the line between them.

SMOTE in Code

The imbalanced-learn library makes SMOTE a two-line affair on your training features and labels.

from imblearn.over_sampling import SMOTE
X_res, y_res = SMOTE().fit_resample(X_train, y_train)

Undersampling the Majority

Undersampling drops majority rows until balance returns. It trains faster but throws away data, which can cost real signal.

When to Pick Which

Oversample when data is scarce and every row matters. Undersample when the majority is huge and you can spare some rows for speed.

The Cardinal Rule

Resample only the training set. Touch the test set and your scores become fantasy, since real data is never rebalanced for you.

Fit on Train Only

SMOTE must learn from training rows alone. Leaking test rows into resampling inflates results and quietly causes data leakage. ⚠️

Resampling Is Not a Cure-All

Balanced counts help, but they are not magic. Pair resampling with the right metrics and sometimes class weights for the best results.

Quick Check

What makes SMOTE different from plain oversampling?

Recap

Resampling balances the training set by oversampling (SMOTE makes synthetic rows) or undersampling. Never resample the test set. 🎯

Frequently asked questions

Is the “Resampling: SMOTE and Undersampling” lesson free?

Yes — the full text of “Resampling: SMOTE and Undersampling” is free to read here on the web, and the Data Science Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Data Science Academy course, upgrade to CoddyKit PRO.

What will I learn in “Resampling: SMOTE and Undersampling”?

Rebalancing the training set. You practise Data Science Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Data Science Academy?

No prior experience is required. Data Science Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Resampling: SMOTE and Undersampling” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Data Science Academy lesson?

Yes. Every Data Science Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Why Accuracy Lies on Imbalance
  2. Resampling: SMOTE and Undersampling
  3. Class Weights and Thresholds
  4. Pick Metrics for Rare Events
← Back to Data Science Academy