Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using imblearn for oversampling multi class data

I want to use RandomOverSampler function from imbalanced-learn module to perform oversampling the data with more than two classes. The following is my code with 3 classes:

import numpy as np
from imblearn.over_sampling import RandomOverSampler

data = np.random.randn(30,5)
label = np.random.randint(3, size=30)

ros = RandomOverSampler(random_state=3)
data_res, label_res = ada.fit_sample(data, label)

After running, it returns this warning:

UserWarning: The target type should be binary. warnings.warn('The target type should be binary.')

But the documentation says:

Notes

Supports mutli-class resampling.

Am I missing something to use it for multi class case? If this is only for binary class, is there any other library or module which supports multi class oversampling?

like image 472
starrr Avatar asked Jul 22 '26 09:07

starrr


1 Answers


I faced the same situation yesterday,
and I used conda to install the library,
I found the file -> base.py
it had something different with the newest version on github.

so I git clone the newest version by github
https://github.com/scikit-learn-contrib/imbalanced-learn

and then,
everythings is ok!
u can use multi-class well

like image 71
林詠翔 Avatar answered Jul 23 '26 23:07

林詠翔