Why this matters
- Fraud, churn, and disease screens are minority-class problems. So is "this RAG answer is unsupported," if most answers are fine and the failures are the ones you care about.
- Accuracy and a single global F1 will congratulate a model that never flags the rare case.
- Interviewers expect the formulas, a worked imbalance example, and a sampling strategy with its downside.
- This is classical supervised learning, and it shows up in AI interviews next to the LLM questions. Treat it as part of the same evaluation literacy.
What imbalance is
An imbalanced dataset has classes with very different counts. A fraud set might be 99 percent legitimate and 1 percent fraud. A leave-ticket classifier might see "balance enquiry" far more often than "harassment complaint." The majority class dominates gradients and dominates naive metrics.
If you do nothing, the model learns the prior: predict the majority. Accuracy can be 99 percent while fraud recall is 0. In the applications that motivated the dataset, the minority class is the point.
What you should notice before you train
- The count gap, not only the accuracy number in a leaderboard screenshot.
- Accuracy is the wrong headline metric. A constant "not fraud" classifier scores the majority rate.
- The minority class usually carries the business or clinical cost.
- You will need a sampling choice, a learning choice, and a metric choice. One of them alone is a partial fix.
Four families of response
| Family | What you do |
|---|---|
| Data | Oversample the minority (random copies, SMOTE, ADASYN), undersample the majority (random or NearMiss), or combine them (SMOTE plus Tomek links to clean overlapping synthetic points). |
| Algorithm | Class weights in logistic regression, SVM, or tree models so a minority error costs more. Cost-sensitive learning. Balanced ensembles such as Balanced Random Forest or EasyEnsemble. |
| Metrics | Precision, recall, F1, ROC-AUC, PR-AUC, and a confusion matrix. Pick the threshold on a validation curve instead of trusting 0.5. |
| Everything else | Collect more real minority examples if you can. Use domain features. For extreme imbalance, consider an anomaly-detection framing. Tune the decision threshold toward the recall you must have. |
Data
What you doOversample the minority (random copies, SMOTE, ADASYN), undersample the majority (random or NearMiss), or combine them (SMOTE plus Tomek links to clean overlapping synthetic points).Algorithm
What you doClass weights in logistic regression, SVM, or tree models so a minority error costs more. Cost-sensitive learning. Balanced ensembles such as Balanced Random Forest or EasyEnsemble.Metrics
What you doPrecision, recall, F1, ROC-AUC, PR-AUC, and a confusion matrix. Pick the threshold on a validation curve instead of trusting 0.5.Everything else
What you doCollect more real minority examples if you can. Use domain features. For extreme imbalance, consider an anomaly-detection framing. Tune the decision threshold toward the recall you must have.
SMOTE (synthetic minority oversampling) invents new minority points along the line between a point and its nearest minority neighbors. It is not a copy paste. It can fill gaps, and it can also invent points that cross into the majority region, especially when classes overlap or the features are noisy. ADASYN focuses synthesis where the minority is harder to learn, near the boundary, which helps recall and can hurt precision.
Undersampling throws away majority points. The model trains faster and the prior shifts, and you may discard useful majority variety. NearMiss keeps majority points that sit close to the minority, which sharpens the border and can overfit that border.
Class weights leave the data alone and tell the loss that a missed fraud is, for example, 20 times worse than a false alarm. This is often the first lever, because it does not fabricate rows. It does not create new information. If you have 50 fraud cases, weights do not become 5,000 real fraud patterns.
A useful picture: before, the majority bar towers over the minority bar. After resampling, the training set the optimizer sees is closer to even. The test set must stay at the real prior. If you resample the test set, your metrics describe a world you do not operate in.
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 4 sections
- Micro F1 and macro F1
- A worked imbalance
- Which one to report
- Limits of the fixes
Test yourself
Answer these before moving on — recall is what makes it stick.