ML0019 Imbalanced Data

How to handle imbalanced data in Machine Learning?

Answer

Imbalanced data (where one class greatly outnumbers the other) skews models toward the majority class and must be handled deliberately. Five complementary techniques: resampling the dataset, by oversampling the minority class (e.g., SMOTE or ADASYN, which synthesize new minority points) or undersampling the majority class; data augmentation to create additional minority variants; class-weight adjustment, assigning a higher misclassification cost to the minority class during training; metric selection, evaluating with precision, recall, F1, or AUC-ROC rather than accuracy, which is misleading under imbalance; and algorithm selection, using specialized learners such as Balanced Random Forest or EasyEnsemble, or ensemble methods whose combined models are more robust to skewed classes.

(1) Data-Level Fixes: Oversample the minority (SMOTE/ADASYN), undersample the majority, or augment minority samples.
(2) Model-Level Fixes: Class weights in the loss, or imbalance-aware algorithms and ensembles.
(3) Evaluation Fix: Never trust accuracy here; measure precision, recall, F1, or AUC.

Imbalanced class distribution and SMOTE synthesizing minority samples

Figure 1: Left: a 9:1 class imbalance. Right: SMOTE creates new minority points along the segments joining existing minority neighbors instead of duplicating them.

Mathematical Formulation:
x_{\mathrm{new}} = x_i + \lambda \, (x_{zi} - x_i), \quad \lambda \sim U(0,1)
\mathcal{L} = \sum_{i} w_{y_i} \, \ell\big(f(x_i), y_i\big), \quad w_{c} \propto \frac{1}{n_c}

Where:

  • x_{\mathrm{new}} is a synthetic minority sample created by SMOTE.
  • x_i is a minority sample and x_{zi} one of its nearest minority neighbors; \lambda is uniform in [0, 1], placing the new point somewhere on the connecting segment.
  • w_{y_i} is the per-sample weight from the class-weighting scheme; \ell is the per-sample loss and f the model.
  • n_c is the number of training samples of class c: the rarer the class, the higher its weight.

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *