Undersampling does not improve model performance


Welcome!

Every Monday, I’ll drop a no-fluff, straight-to-the-point tip on a data science skill, tool, or
method to help you stay sharp in the field. I hope you find it useful!


My Hyperparameter Optimization Course Just Got a Major Update!

I’ve released a completely updated version of my course, now called Master Hyperparameter Optimization for Tabular Learning. It focuses on optimizing today’s leading tabular models using the tools and techniques the machine-learning community relies on, including Optuna, Bayesian optimization, successive halving, and Hyperband.


Undersampling does not improve model performance

When faced with an imbalanced dataset, one of the most common recommendations is to balance the classes before training the model.

The simplest way to do this is undersampling: remove observations from the majority class so that its size becomes closer to that of the minority class.

It sounds reasonable. If the model sees both classes in similar proportions, surely it will pay more attention to the rare one.

But there is a rather uncomfortable detail: We are throwing away data we went through the trouble of collecting. And that’s rarely a good idea.

What undersampling methods actually do

Random undersampling removes majority-class observations at random until a chosen class ratio is reached, often 1:1.

Cleaning methods are more selective. They use rules based on nearest neighbours, class overlap, or instance hardness to decide which majority-class observations look redundant, noisy, or difficult, and remove those instead.

For example, Edited Nearest Neighbours removes majority observations whose nearest neighbours disagree with their class. Tomek Links removes majority observations that form very close opposite-class pairs. Condensed Nearest Neighbours tries to retain only the observations needed by a one-nearest-neighbour classifier.

Why did undersampling seem like a good idea?

Let’s take a look at the history.

Many of these methods were introduced long before the ensemble models we routinely use today. Condensed Nearest Neighbours appeared in 1968. Edited Nearest Neighbours followed in 1972. Tomek Links, Repeated ENN, and AllKNN arrived in 1976. One-Sided Selection was proposed in 1997, Neighbourhood Cleaning Rule in 2001, and NearMiss in 2003.

At the time, researchers commonly worked with nearest-neighbour classifiers, linear machines, and individual decision trees. Computing resources were limited, datasets were smaller, and simplifying the training set could make both computational and statistical sense.

Then random forests and gradient-boosting machines changed the modelling landscape. Yet the old recommendation survived: balance the data first

So I put it to the test.

Show me the data

For my book, Imbalanced Data: Myths, Mistakes and Modern Solutions, I evaluated undersampling across 37 datasets with different sizes and imbalance ratios.

I combined the undersampling methods with widely used ensemble models: random forests, scikit-learn’s gradient boosting machine, CatBoost, XGBoost, and LightGBM. I evaluated discrimination with ROC-AUC and the quality of the predicted probabilities with the Brier score. I also accounted for variability instead of treating every tiny numerical difference as an improvement.

The following figure zooms in on random undersampling for five representative datasets. The datasets contain between 50,000 and 280,000 observations, with imbalance ratios ranging from 3:1 to almost 600:1.

As we can see in the image, random undersampling does not make the models better at discriminating between the classes, and it deteriorates the calibration of their outputs. The result is remarkably consistent.

Look at the left-hand panels. The green ROC-AUC values are usually similar to, and sometimes lower than, their blue counterparts. Undersampling did not give the models new information with which to rank positive observations above negative ones.


Now look at the right-hand panels. The Brier scores increase sharply after undersampling. In other words, the predicted probabilities become less accurate.

If undersampling does not work, what should we do instead?

Train a strong classifier on the original class distribution. Evaluate it with a metric that matches the question you care about and report the uncertainty around that estimate. If you need a different trade-off between false positives and false negatives, adjust the decision threshold after training.

You can find the complete experiments in this GitHub repository. Please give it a star if you find it useful.

If you liked this article, you’ll also enjoy my new book: Imbalanced Data: Myths, Mistakes and Modern Solutions.

I hope this information was useful!

Wishing you a successful week ahead - see you next Monday! 👋🏻

Sole


Ready to enhance your skills?

Our specializations, courses and books are here to assist you:


Hi…I’m Sole
I’m a Python developer, AI educator, and developer advocate. I’m the creator and maintainer of Feature-engine and the main instructor at Train in Data.
I share practical Python lessons, open-source insights, and ideas to help our community build better software and grow as developers and data scientists.

You are receiving this email because you subscribed to our newsletter, signed up on our website, purchased or downloaded any products from us.


Follow us on social media

Copyright (C) 2026 Train in Data. All rights reserved.


Unsubscribe · Preferences

Train in Data

by Soledad Galli, PhD | Data scientist | Python Developer | Best-selling instructor | Book author | 👉 www.trainindata.com

Read more from Train in Data
Why optimise for calibration if I can recalibrate later?

Welcome! Every Monday, I’ll drop a no-fluff, straight-to-the-point tip on a data science skill, tool, ormethod to help you stay sharp in the field. I hope you find it useful! Machine Learning Interpretability course has been updated! I’ve recently finished updating my Machine Learning Interpretability course. 🎉 I’ve refreshed the course notebooks, replacing outdated libraries with practical alternatives and adding fixes to keep examples running as Python evolves. You’ll explore the same...

TunedThresholdClassifierCV: the good, the bad, the ugly

Welcome! Every Monday, I’ll drop a no-fluff, straight-to-the-point tip on a data science skill, tool, ormethod to help you stay sharp in the field. I hope you find it useful! TunedThresholdClassifierCV: the good, the bad, the ugly For years, scikit-learn classifiers made one decision for us: predict() converted probabilities into class labels using a de facto cut-off of 0.5. That number seems obvious from stats classes. But in practice, it’s rarely the right one. A threshold is not a property...

Class imbalance makes metrics volatile

Welcome! Every Monday, I’ll drop a no-fluff, straight-to-the-point tip on a data science skill, tool, ormethod to help you stay sharp in the field. I hope you find it useful! Have you added it to your reading list yet? Imbalanced Data, Myths, Mistakes and Modern Solutions Imbalanced data isn't a problem. How you handle it is. My book, Imbalanced Data: Myths, Mistakes and Modern Solutions, cuts through the common misconceptions and brings together practical, evidence-based approaches you can...