Back to Supervised Learning

Class Imbalance — SMOTE, Class Weights, Threshold Adjustment

When 1% of your data is the class you care about. Three strategies for handling it. FIND_VIDEO: search 'class imbalance SMOTE class weight' — recommended channel: StatQuest. Aim for 10 min or under.

18 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

Ready to continue?

Mark this lesson as complete when you're ready to proceed.

Key moments

  1. SMOTE IntroductionSMOTE creates new synthetic data points for the minority class to maintain data diversity and reduce overfitting.
  2. Synthetic Generation TheoryNew synthetic examples are generated by interpolating between two existing minority class examples.
  3. SMOTE Mechanism StepsSMOTE identifies the minority class, selects an instance, finds its K-Nearest Neighbors, and interpolates.
  4. SMOTE Formula and NoiseThe synthetic point S1 is calculated using X + R * (X - X1); noise occurs when interpolation crosses into the majority class region.
  5. Borderline-SMOTE NeedBorderline-SMOTE addresses the issue of noisy synthetic samples generated near the boundary of the majority class.
  6. Borderline-SMOTE StepsBorderline-SMOTE identifies minority instances near majority instances and only interpolates within minority neighbors.
  7. SMOTE ImplementationSMOTE is imported from imblearn, applied to the training data using sampling_strategy='minority', and data is normalized.
  8. Borderline-SMOTE ImplementationBorderline-SMOTE is implemented similarly to SMOTE, resampling the training data before normalization and model training.
  9. Result ComparisonResults show that SMOTE and Borderline-SMOTE yield significantly better F1 scores than the imbalanced baseline model.
PDF notes

Frequently asked questions

How does SMOTE differ from simple random oversampling?

SMOTE creates new, synthetic data points via interpolation, whereas random oversampling simply duplicates existing minority points.

Why is Borderline-SMOTE necessary?

Traditional SMOTE can generate noisy synthetic examples if minority points are close to majority points, which Borderline-SMOTE avoids.

What is the role of R in the SMOTE formula?

R is a random number between 0 and 1; it determines where the new synthetic point lies on the line segment between the two chosen minority points.

Should I apply SMOTE to the test set?

No, SMOTE should only be applied to the training data to prevent data leakage and ensure realistic evaluation.