starrr
starrr

Reputation: 1023

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?

Upvotes: 3

Views: 6665

Answers (3)

BELMALLEM Marouane
BELMALLEM Marouane

Reputation: 1

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.

Upvotes: 0

Bani
Bani

Reputation: 111

You need to update imblearn using :

pip install -U imbalanced-learn

Upvotes: 0

林詠翔
林詠翔

Reputation: 21


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

Upvotes: 2

Related Questions