internalsGet Pro

Module 07 · Lesson 8 of 12Pro

Imbalanced classes: when positives are rare

Level
Intermediate
Topic
Classical ML: regression and classification
Reading time
16 min

When you finish this page you can

  1. Explain why accuracy hides a model that never finds the rare class, and report average precision, recall and precision instead.
  2. Predict what class weights, undersampling and SMOTE do to a model’s chances, and correct the odds afterwards.
  3. Set a decision threshold from the cost of a missed positive and the cost of a false alarm.
  4. Split rare-class data with stratify so every set holds its share of positives.
  1. Train, validation and test sets13 min
  2. Logistic regression: predicting probabilities13 min
  3. Gradient boosting: XGBoost, LightGBM and CatBoost18 min

A 99.83% score that catches no fraud

is our example online store. Farah, an ML engineer on its ML team, is building a model that answers one question for each card payment: is it fraud?

Our biggest sale ever · Black Friday

Flat 50% Off

Pro

Continue reading

Unlock every course, now and later

  • System Design, live
  • AI Engineering, live
  • Data Engineering, live
  • Machine Learning Engineering, live
  • Inference Engineering, coming soon
  • AI Research, coming soon
  • Performance Engineering, coming soon
  • Agent & Harness Engineering, coming soon
  • LLM Fine-tuning, coming soon
  • LLM Pre-training & Post-training, coming soon
  • Reinforcement Learning, coming soon
  • AI Infrastructure & Platform Engineering, coming soon
  • AI Evaluation & Safety, coming soon
  • Forward Deployed Engineering, coming soon
  • Cloud Computing, coming soon
  • DevOps, coming soon

50% off · Annual and Lifetime

BLACKFRIDAY50Applied at checkout

Choose a plan