Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Machine Learning for Imbalanced Data

You're reading from  Machine Learning for Imbalanced Data

Product type Book
Published in Nov 2023
Publisher Packt
ISBN-13 9781801070836
Pages 344 pages
Edition 1st Edition
Languages
Authors (2):
Kumar Abhishek Kumar Abhishek
Profile icon Kumar Abhishek
Dr. Mounir Abdelaziz Dr. Mounir Abdelaziz
Profile icon Dr. Mounir Abdelaziz
View More author details

Table of Contents (15) Chapters

Preface Chapter 1: Introduction to Data Imbalance in Machine Learning Chapter 2: Oversampling Methods Chapter 3: Undersampling Methods Chapter 4: Ensemble Methods Chapter 5: Cost-Sensitive Learning Chapter 6: Data Imbalance in Deep Learning Chapter 7: Data-Level Deep Learning Methods Chapter 8: Algorithm-Level Deep Learning Techniques Chapter 9: Hybrid Deep Learning Methods Chapter 10: Model Calibration Assessments Index Other Books You May Enjoy Appendix: Machine Learning Pipeline in Production

Random oversampling

The simplest strategy to balance the imbalance in a dataset is to randomly choose samples of the minority class and repeat or duplicate them. This is also called random oversampling with replacement.

To increase the number of minority class observations, we can replicate the minority class data observations enough times to balance the two classes. Does this sound too trivial? Yes, but it works. By increasing the number of minority class samples, random oversampling reduces the bias toward the majority class. This helps the model learn the patterns and characteristics of the minority class more effectively.

We will use random oversampling from the imbalanced-learn library. The fit_resample API from the RandomOverSampler class resamples the original dataset and balances it. The sampling_strategy parameter is used to specify the new ratio of various classes. For example, we could say sampling_strategy=1.0 to have an equal number of the two classes.

There are...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}