In life, some events are rare and most cases are normal. So I am wondering, to detect the rare cases, shall we use an imbalanced dataset with more historical rare cases?

Taking the German Credit Data, as an example. It contains data on 20 variables and the classification whether an applicant is considered a Good or a Bad credit risk for 1000 loan applicants. 70% are Good. 30% Bad.

With this original data set, I assume the model would incline to better recognize the normal cases (because more normal cases in the data)

If a balanced dataset is used, i.e. the number of good credits equals to that of bad credits, a final model will be good at predicting both ‘Good’ and ‘Bad’.

But if we want to use machine learning to recognize the rare events, e.g. in this case, the bad credit customers. Shall we use an imbalanced dataset (for example 70% Bad credits, 30% Good in total 1000 records), that contains much more bad credit customers, than good ones, so the final model is good at recognizing the bad customers? Or a balanced dataset is always necessary (also the only right way).

Can anybody please shed some light on this?

Thank you.

Link to data: https://online.stat.psu.edu/stat857/sites/onlinecourses.science.psu.edu.stat857/files/german_credit/index.csv


1 Answer 1


Impact of imbalanced datasets

First I would say that imbalanced dataset impact depends on the type of model you are using.
For instance:

  • Gaussian Naive Bayes should not be that much impacted if you have a certain amount of data for each class that is enough to approximate your gaussian distributions. (and that your data are normally distributed)
  • Neural Networks learning is using the error of your predictions to update its model, so having an imbalanced dataset would lead to imbalanced learning (for example 70% of the weights/biais have been updated according to class 'Good'). You don't want this happening a priori.

How to deal with imbalanced dataset ?

There might be other approaches, but you can do at least:

  • Use an algorithm that is not much impacted by imbalanced datasets

  • Some algorithms have a class_weight parameter. You can use it to penalize more the minority class during the learning process so the model is forced to pay more attention to the minority class observations. See this post for more details: How does the class_weight parameter in scikit-learn work?

  • Resample your dataset so it becomes balanced. That could be through undersampling the majority class or oversampling the minority one.

Further reading

How to Deal with Imbalanced Data
8 Tactics to Combat Imbalanced Classes in Your Machine Learning Dataset

Hope it helps.

  • $\begingroup$ thank you for sharing the knowledge! $\endgroup$
    – Mark K
    Nov 6, 2020 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.