Foundations to Frontier
Tests
D. Classical Machine Learning › D0 Core Concepts (concept pages)

Imbalanced Data: SMOTE, ADASYN, Undersampling and Class Weights

In many real problems the interesting class is rare: faults, fraud, anomalies, defects. A model trained naively may almost never predict it. Common remedies change the training data (random oversampling, undersampling, synthetic minority examples with SMOTE or ADASYN) or the loss (class weights). This page explains each technique, what it actually changes in the model, and its side effects on calibration and on the information kept, and it compares them with the simplest alternative: keep the data and move the decision threshold. In the exercises you implement every technique from scratch; then you measure, on data with 2% positives, whether rebalancing improves ranking, F1 or calibration compared with a plain model whose threshold is tuned.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

When one group is tiny

Imagine learning to spot rare red marbles in a jar where only 2 in 100 are red. If you always guess “blue”, you are right 98% of the time but never find a red one. One fix is to practise on extra copies of the red marbles, or to throw out some blue ones, so you see the reds more often. Another is to give a big prize for finding a red one. A third is simply to say “red” whenever a marble looks even a little bit red.

Rebalancing versus moving the threshold
purple boundary (plain at 0.5): finds 9/12 minority, 2 false alarms · dashed (plain at t): 9/12, 2 false alarms
Rebalancing mostly slides the boundary toward the majority class, which a lower threshold on the plain model also does, without inventing points (SMOTE, rings), duplicating them, or discarding majority data (faded). Rebalancing also inflates the predicted probabilities, so they are no longer calibrated.
Why engineers care

Failures, anomalies and hazards are rare by design. How you handle imbalance decides whether a detector finds anything at all, and whether its probabilities can be trusted in a risk calculation.

📝 Quick check (Level 0)
0/3 answered
  1. 1. With 2% positives, always predicting negative gives accuracy…
  2. 2. Making copies of the rare examples is called…
  3. 3. In the demo, lowering the plain model's threshold…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

The toolbox

Technique What it does Side effects
class weights multiply the loss of minority examples by w probabilities inflated
random oversampling duplicate minority examples same effect as weights in expectation; overfitting risk for flexible models
random undersampling drop majority examples loses information; fast
SMOTE interpolate new minority points between minority neighbours can create points in majority regions
ADASYN SMOTE focused on hard minority points near the boundary amplifies noise
threshold moving keep the data, lower the decision threshold none; needs a validation set
better metric PR-AUC, recall at fixed precision, MCC —
from sklearn.linear_model import LogisticRegression
LogisticRegression(class_weight="balanced").fit(X, y)
from imblearn.over_sampling import SMOTE, ADASYN                 # imbalanced-learn package
from imblearn.pipeline import make_pipeline                      # resample only inside training folds
pipe = make_pipeline(SMOTE(k_neighbors=5), LogisticRegression())
📝 Quick check (Level 1)
0/3 answered
  1. 1. SMOTE creates new examples by…
  2. 2. class_weight='balanced' sets weights…
  3. 3. Resampling must be done…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

What rebalancing really changes

Weights and duplicates. For a probabilistic model, weighting positives by w multiplies the fitted odds by about w. This is equivalent to shifting the logit by log w, the same as using threshold 1/(1 + w) on the original model. Oversampling by a factor w does the same in expectation.

So rebalancing mostly moves the decision boundary, and in return destroys calibration: a model trained on 50/50 data reports probabilities as if positives were common. The probabilities can be corrected with the prior-shift formula (D0.10).

Synthetic data. SMOTE can also change the boundary’s shape by filling the minority region, which helps some high-variance models but can bridge into majority regions when minority clusters are spread out.

Undersampling throws away majority examples and so raises variance, though it can be combined with ensembles (EasyEnsemble, balanced random forests).

🐍 Exercise 1: rebalancing from scratch
Implement random over- and undersampling, SMOTE (interpolation to minority neighbours), ADASYN (more synthetic points near minority examples surrounded by the majority), 'balanced' class weights, a sample-weighted logistic regression and balanced accuracy; check counts, that synthetic points stay within the minority range, and that weighting raises balanced accuracy.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Weighting positives by 10 is roughly equivalent to…
  2. 2. After training on 50/50 resampled data, probabilities are…
  3. 3. ADASYN puts more synthetic points…

Level 3: Advanced

★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.

A practical recipe

  1. Use the right metrics: PR-AUC, recall at a required precision, cost (D0.8, D0.9).
  2. Train a strong model on the original data and choose the threshold on validation data from costs or constraints.
  3. If the learner struggles to pay attention to the minority class (for example few positives per tree split), try class weights first: cheap and equivalent to oversampling.
  4. Try SMOTE-like methods only as a tuned hyperparameter inside cross-validation. Gains are dataset-specific and often vanish with strong learners such as gradient boosting.
  5. If probabilities matter, recalibrate after rebalancing.
  6. Better than any resampling: more minority data (targeted collection, simulation, augmentation that respects physics).

Interview questions.

  • Does SMOTE help gradient boosting? Rarely. Strong learners plus threshold tuning usually match or beat it (van den Goorbergh et al., 2022; Elor & Averbuch-Elor, 2022).
  • Why is undersampling sometimes used anyway? It speeds up training on huge majority classes; bagging over many undersamples recovers the lost information.
📝 Quick check (Level 3)
0/3 answered
  1. 1. The first thing to try for a 1% positive class:
  2. 2. Balanced random forests combine…
  3. 3. If calibrated probabilities are needed after class weighting…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Does rebalancing help?

Exercise 1. With 190 majority and 10 minority points:

  • balanced class weights are 0.526 and 10.0;
  • SMOTE’s synthetic points stay inside the minority range;
  • ADASYN allocates exactly the requested 40 points across the 10 minority examples;
  • weighting lifts balanced accuracy from 0.95 to 0.99.

Exercise 2: 2% positives. Setup:

  • logistic regression on quadratic features;
  • each method is fitted on 70% of 3 000 training cases, and the remaining 30% chooses an F1-optimal threshold;
  • 20 000 test cases, 12 repetitions.
Method ROC-AUC PR-AUC F1 at 0.5 F1 at tuned threshold ECE
no rebalancing 0.925 0.415 0.299 0.419 0.008
class weights 0.940 0.410 0.211 0.425 0.181
random oversampling 0.940 0.409 0.209 0.426 0.182
random undersampling 0.935 0.366 0.196 0.391 0.193
SMOTE 0.940 0.404 0.218 0.406 0.168
ADASYN 0.939 0.395 0.198 0.403 0.186
  • Once the threshold is tuned, all methods land within 0.035 F1 of each other. The plain model goes from 0.299 to 0.419 just by lowering its threshold.
  • At the default 0.5, the rebalanced models are worse than the plain one: they now raise too many alarms.
  • Rebalancing gave a slightly better ROC-AUC (+0.015, partly faster convergence of the rare-class terms) but no better PR-AUC.
  • Undersampling lost information: PR-AUC drops by 0.05.
  • Every rebalancing method destroyed calibration (ECE 0.17–0.19 against 0.008).

The threshold, not the data, was the problem.

🐍 Exercise 2 (research): rebalancing versus threshold tuning
On data with 2% positives, train logistic regression with no rebalancing, class weights, random over- and undersampling, SMOTE and ADASYN; compare ROC-AUC, PR-AUC, F1 at threshold 0.5 and at a validation-tuned threshold, and calibration error on 20 000 test cases.

Imbalanced learning in AI, robotics and aerospace

  • Fault and anomaly detection: failures are rare; simulation and fault injection add minority data more reliably than SMOTE.
  • Rare-object detection: focal loss and class-balanced sampling in detectors (E sections).
  • Conjunction (collision) risk screening: extreme imbalance; threshold choice is driven by risk tolerance.
  • Predictive maintenance: class weights in gradient boosting, plus calibrated probabilities for maintenance planning.

References

  1. N. V. Chawla, K. W. Bowyer, L. O. Hall, W. P. Kegelmeyer (2002). “SMOTE: synthetic minority over-sampling technique.” JAIR 16.
  2. H. He, Y. Bai, E. A. Garcia, S. Li (2008). “ADASYN: adaptive synthetic sampling approach for imbalanced learning.” IJCNN.
  3. H. He, E. A. Garcia (2009). “Learning from imbalanced data.” IEEE TKDE 21(9).
  4. R. van den Goorbergh, M. van Smeden, D. Timmerman, B. Van Calster (2022). “The harm of class imbalance corrections for risk prediction models.” JAMIA 29(9).
  5. Y. Elor, H. Averbuch-Elor (2022). “To SMOTE, or not to SMOTE?” arXiv:2201.08528.