Imbalanced & messy data

Class weights vs resampling vs threshold moving, missing values, outliers. Fraud, churn, and credit — the bread-and-butter Indian ML interview datasets.

About 19 min read3-question knowledge check

The mental model

Imbalanced classification is airport security screening. Threats are one in a thousand, so a guard who waves everyone through is 99.9% "accurate" and catches nothing. The whole discipline is not about accuracy — it is about the cost of the two mistakes: waving a threat through (false negative) versus stopping an innocent traveller (false positive). You tune the screening sensitivity to where those costs balance, and you measure success by how many real threats you catch at an acceptable false-alarm rate — never by the fraction of correct decisions.

That reframing is the entire subject. A model has three independent levers, and confusing them is the most common mistake:

  1. What the model optimizes — the loss. Class weights and custom losses make the minority class count more so the optimizer does not ignore it.
  2. What data the model sees — resampling. Oversampling the minority (SMOTE, duplication) or undersampling the majority changes the training distribution.
  3. Where you draw the line — the decision threshold. A model outputs a probability; turning it into a yes/no at 0.5 assumes balanced classes and equal error costs, which imbalanced problems never have.

The WHY that matters: these levers do different jobs and are often confused. Threshold moving is free, reversible, and needs no retraining — you should almost always try it first. Class weights are the next-cheapest. Resampling is the most invasive and the easiest to get wrong (it must happen inside cross-validation, never before the split, or you leak). "Messy data" — missing values and outliers — sits underneath all of this: the minority class is where messy data hurts most, because a handful of mislabeled or corrupted rows in a 0.3% class is a large fraction of your signal.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision
Imbalanced & messy data — AI/ML lesson · PrepAtlas Tech