Using imblearn for oversampling multi class data

Viewed 5056

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?

3 Answers

You need to update imblearn using :

pip install -U imbalanced-learn

RandomOverSampler() works very well for me on a multi-class problem with 9 labels I see on your code that you are using ada oversampler instead of ros that you defined.

Related