简体   繁体   中英

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM