← the late compiler
C_000067 · machine learning · intermediate

Class Imbalance

When one class vastly outnumbers others, so a model can score well by ignoring the minority entirely.

Step 1 of 4

In words

What it is, why it matters, and what it is like.

Why am I learning this?

This concept is the gateway to several others in your library. It appears in Feature Selection (when you pick which features to keep, you must account for imbalance to avoid choosing ones that only help the majority class), Feature Stores (your training-serving pipeline must preserve the same imbalance or your model will fail in production), Imbalanced Data (the general problem of skewed distributions across any dimension), and Drift Detection (a shift in class balance is one of the first warning signs your model is degrading). Master it here, and you will be ready to understand how every real-world model, from fraud detection to medical diagnosis, is evaluated and corrected.

The idea, in plain terms

Imagine you are teaching a child to spot a rare bird. You show them a thousand pictures of pigeons and only ten of the rare bird. After a while, the child learns to say 'not the rare bird' to everything—and they are right 99% of the time. They have learned a rule that is almost always correct, but it is useless. A model does exactly the same thing. When one class vastly outnumbers another, the model can achieve a high accuracy score by always predicting the majority class. The model is not broken; it is doing exactly what it was trained to do—minimise the number of mistakes it makes. But a mistake that misses a rare cancer is not the same as a mistake that mislabels a healthy scan. The cost of errors is asymmetric, but accuracy treats every mistake as equally costly. So the first lesson of class imbalance is that accuracy becomes meaningless long before the model becomes useless. The second lesson is that you cannot just add more data—the imbalance is often a fact of the world, not a data collection error. The third is that you have a toolkit of responses: resample the data so the classes are more balanced, give the model different weights for different classes, and tune the threshold at which the model says 'yes'. Each of these changes what the model optimises, and each has a price. The goal is not to make the model perfectly balanced—it is to make it good at the task that actually matters.

An analogy

Think of a security guard at an airport. They have to spot a smuggler in a stream of thousands of innocent travellers. If they stop everyone, they catch all smugglers but anger every passenger. If they stop no one, they miss all smugglers but keep the line moving. The guard's job is not to maximise the number of correct decisions in raw terms—it is to balance the cost of a false alarm (a delayed traveller, a lawsuit) against the cost of a missed smuggling attempt (a bomb on a plane). The guard has three tools: they can change how they look at the crowd (resampling—maybe they get more informants, or they ignore some obvious innocents), they can be more cautious by default (class weights—they raise their baseline suspicion), or they can change what they do with a borderline suspicion (threshold tuning—they only arrest when they are very sure, or they arrest on a hunch). The analogy breaks down when you remember that a model does not have judgment or fear—it has a single number that it compares to a threshold. The guard can weigh dozens of signals instantly; a model weighs what you give it, and if you give it only the crowd size and the number of suspicious glances, you have already limited it. Also, resampling is not free—you are discarding data or creating fake data, and that has its own risks. But the guard's core problem—minimising a cost that is not symmetrical—is exactly the model's problem.

Definition

Class imbalance is the situation where the number of examples in one class (the majority) vastly exceeds the number in another (the minority), so that a model can achieve high accuracy by always predicting the majority class, making accuracy a misleading metric and requiring special techniques to learn the minority class.

Where this sits

This concept builds on nothing you have learned yet, but it connects to several topics in your library. It is a part of Feature Engineering, because your features and your data distribution are the raw material your model sees. The Imbalanced Data note is the general problem—this concept is the specific case where the imbalance is between classes of a supervised problem. Feature Selection interacts with it because if you select features on an imbalanced set, you may choose features that only help the majority. Data Quality is related because a mislabelled minority example can be fatal when you have few of them. You will also need this concept before you can understand Drift Detection, because a shift in class balance is a form of drift that you must be able to recognise.

Signal from the Frontier

Get the next essay on mind, machine, and meaning

Essays at the intersection of AI, philosophy, and Indian governance. No promotional content.

We'll send a one-click sign-in link to confirm. No password needed.

Views expressed are personal and do not represent the Government of India or the Government of Uttarakhand.