Classification: lesson 5 of 5
Classification
Class Imbalance Fundamentals
Recognize the risks of rare positive classes before selecting a model or metric.
Concept
Class imbalance occurs when one class is much more common than another. In fraud data, 99% of transactions might be legitimate and 1% fraudulent. The rare class is often the one a team cares most about, which makes overall summaries easy to misread.
Why Accuracy Can Mislead
Imagine 990 legitimate transactions and 10 fraud cases. A useless classifier that predicts "legitimate" for every transaction is correct for 990 rows, or 99% accuracy, while detecting zero fraud. The number sounds strong but fails the business purpose.
This does not mean accuracy is always useless. It means a single overall number can hide failure on the class that matters. The published evaluation lesson, Why Accuracy Is Not Enough, develops precision, recall, F1, ROC-AUC, and metric choice in detail. This lesson establishes why that deeper evaluation is needed.
What Imbalance Changes
The minority class supplies fewer examples, so its patterns can be harder for a model to learn. A model may favor common majority patterns and still appear successful overall. Teams should inspect class-specific behavior, decision thresholds, data collection quality, and the cost of different mistakes.
Consider a rare disease screen. Missing a true case may be costly, while flagging someone who is healthy can cause anxiety and follow-up testing. In equipment-failure prediction, an unnecessary maintenance inspection and a missed failure have different operational costs. In churn, the class may be less extreme, but the positive class can still be smaller and strategically important.
False Positives and False Negatives
When a classifier predicts the positive class incorrectly, that is a false positive. When it predicts negative for an actual positive case, that is a false negative. You do not need a full confusion matrix yet to reason about them. Ask which error is more harmful, who experiences it, and whether the organization can act on more flagged cases.
Thresholds matter here. A lower fraud threshold may capture more suspicious transactions but also create more reviews. A higher threshold may conserve review capacity while missing more cases. Module 4 will provide the tools to measure and compare these trade-offs.
What Not to Do
Do not assume every dataset should become 50/50. Do not blindly delete majority examples, duplicate minority examples, or change class balance before understanding the problem. Such methods can be useful later, but they can also distort data or leak information if applied incorrectly across train/test boundaries. First define the positive class, inspect its frequency, and understand the business cost of errors.
Practical Workflow
- Count examples in each class and verify label quality.
- Identify the class and error type that matters most.
- Keep train, validation, and test boundaries honest.
- Review more than overall accuracy.
- Decide how predictions will be acted upon before changing data or thresholds.
This workflow connects class imbalance to responsible model evaluation rather than treating imbalance as an automatic data-cleaning problem.
Failure Signals
Common Mistakes
- Declaring a 99% accurate fraud model useful without checking fraud detection.
- Assuming minority always means unimportant.
- Forcing a balanced dataset without a reason.
- Resampling before splitting and contaminating held-out data.
- Ignoring whether teams can handle the volume of positive predictions.
Best Practices
Start with the real class frequency and decision context. Report performance for the class of interest, inspect error consequences, and keep the final test set representative of the expected world. Collecting better minority-class examples can be more valuable than immediately changing algorithms.
Interview Perspective
Question: Why can a 99% accurate fraud classifier be useless? Answer: if fraud is rare, always predicting the majority class can achieve 99% accuracy while detecting no fraud. What the interviewer is testing: whether you connect evaluation to class distribution and business harm. Follow-up: what would you inspect beyond accuracy?
Practice Questions
- A security dataset has 99.5% normal events. Why is accuracy alone insufficient?
- Which error is a false negative in disease screening?
- Why is making every dataset 50/50 not automatically correct?
- How can lowering a threshold affect a fraud-review team's workload?
- Why should resampling never contaminate the final test set?
Quick Quiz
- What is class imbalance? Answer: substantially unequal class frequencies.
- Can a majority-only classifier have high accuracy? Answer: yes.
- Does imbalance automatically require deleting majority examples? Answer: no.
Module 3 Synthesis
Classification starts with a class target, produces scores or probability-like outputs, applies thresholds to make decisions, extends from binary to multiclass settings, and requires special care when classes are unequal. These ideas create the need for Model Evaluation and Selection: one number alone cannot judge a classifier responsibly.
Key Takeaway
Key Takeaways
Rare classes can be the most important classes. Class imbalance changes how model quality, thresholds, and operational decisions must be interpreted.
Next Lesson
Next, begin Module 4 and learn how baselines and evaluation measures help compare models responsibly.
Finish this lesson on your terms
Mark it complete when you have worked through the material and are ready to move on.