Rawnak Yazdani
Rawnak Yazdani

Reputation: 1411

How to specify an exact undersample/oversample number for each class using "imblearn" library in Python?

I am working with "imblearn" library for undersampling. I have four classes in my dataset each having 20, 30, 40 and 50 number of sample data(as it is an imbalanced class). These sample numbers are chosen to describe the problem easily, these are not efficient amount in practical.

I want to undersample each class having 10 sample data. Is there a possible way I can do it using "imblearn"?

Currently I am undersampling each class to the number my minority class have(20 sample data) using the following code:

undersample = RandomUnderSampler(sampling_strategy='all')
X_under, y_under = undersample.fit_resample(X, y)

Upvotes: 1

Views: 1267

Answers (1)

ramobal
ramobal

Reputation: 261

you can pass a dictionary to sampling_strategy: undersample=RandomUnderSampler(sampling_strategy={0:10,1:10,2:10,3:10})

Upvotes: 2

Related Questions