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
Only 1% of records are positive. Which metric is most informative for the positive class?
- Accuracy
- Area under the precision-recall curve
- R-squared
- 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.
Which techniques help with an imbalanced training set?
- Class weights that penalize minority errors more
- Randomly undersampling the majority class
- Dropping the minority class entirely
- Generating synthetic minority samples with SMOTE on the training split
- 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.
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.
