Class Imbalance
A smoke detector that never beeps is right 99.9% of the time and worthless 100% of the time. When fraud, disease or churn is rare, accuracy rewards the model for ignoring exactly the class you care about. This topic covers better metrics, resampling, and cost-sensitive loss.
01.The Problem: A Detector That Never Beeps
Consider a smoke detector.
Out of 10,000 days, there is exactly 1 real fire.
Detector A: never beeps. It is "correct" on 9,999 of 10,000 days — 99.99% accuracy. It also burned the house down.
Detector B: beeps on the fire, and on 20 false alarms. Accuracy "only" 99.8%. It saved the house.
Which detector do you buy?
Obviously B — yet if you judge by accuracy, A wins. That mismatch is class imbalance: when one class (fraud, disease, churn, fire) is rare, plain accuracy becomes meaningless, because the majority class dominates everything.
Same story in fraud detection with only 0.1% fraudulent transactions:
- a model predicting "not fraud" every single time is 99.9% accurate,
- and completely useless — it catches zero fraud.
Worse, training actively rewards this: the loss is averaged over all rows, and 999 of 1000 rows are negative, so a model that ignores the minority class minimizes the loss. The model is literally paid to look away.
Why Accuracy Fails on Rare Classes
Why Accuracy Fails on Rare Classes
A 99/1 split lets a trivial all-negative classifier score 99% accuracy while detecting nothing, so imbalance demands different metrics and strategies.
Unlock Topic #38: Class Imbalance
You are viewing a preview. The full in-depth technical walkthrough, worked derivations, and code notebooks for this concept, along with self-assessment quizzes, are available with Pro or Lifetime Access.
Failure modes, high-throughput bottlenecks, and real FAANG implementation decisions.
Interactive system topology diagrams, live parameter simulators, and downloadable SVG charts.
Staff-level multiple-choice quiz questions with instant feedback and answer explanations.
Firebase Google authentication automatically syncs your completed topics and quiz scores.
How clear and actionable was this distributed systems breakdown?