Bitzu

Machine Learning Associate ยท Algorithms, pipelines and imbalance

Mitigating class imbalance

Methods for imbalanced training data: resampling (over/under-sampling, SMOTE), class weights or cost-sensitive learning, appropriate metrics, and stratified splits.

Key points

  • When one class is rare, a model can score high accuracy by ignoring it.
  • Options: resample the training set (oversample the minority, undersample the majority, or synthesize points with SMOTE), use class weights so minority errors cost more, and judge the model with precision, recall, F1 or PR AUC instead of accuracy.
  • Split with stratification and resample only the training portion, never the test set.

Source: https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html

Practice questions

Single choice

Only 1% of records are positive. Which metric is most informative for the positive class?

  1. Accuracy
  2. Area under the precision-recall curve
  3. R-squared
  4. Mean absolute error
Show answer

Answer: B. Area under the precision-recall curve

Precision-recall focuses on the rare class. Accuracy can reach 99% by predicting only the majority, and R-squared and MAE are regression metrics.

Select all that apply

Which techniques help with an imbalanced training set?

  1. Class weights that penalize minority errors more
  2. Randomly undersampling the majority class
  3. Dropping the minority class entirely
  4. Generating synthetic minority samples with SMOTE on the training split
  5. Judging the model by accuracy only
Show answer

Answer: A. Class weights that penalize minority errors more, B. Randomly undersampling the majority class, D. Generating synthetic minority samples with SMOTE on the training split

Weights, undersampling and SMOTE on training data all rebalance learning. Dropping the minority removes what you want to predict, and accuracy alone hides the problem.

True or false

It is safe to oversample the minority class on the full dataset before splitting into train and test sets.

Show answer

Answer: False

Duplicated or synthetic minority rows would land in both splits, leaking training information into the test set and inflating scores. Split first, then resample only the training data.

Practice 8 questions on this topic in Bitzu

Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.

Download on the App StoreGet it on Google Play

More Machine Learning Associate topics in this module