pythonpython-3.ximblearn

Python: name 'RandomOverSampler' is not defined


Am trying to use imblearn to do some over and under sampling on a dataframe. However when calling either function (e.g. RandomOverSampler), it says that it is not defined.

the imblearn library is included

import imblearn

when calling print(imblearn.version) , it also prints the version number 0.8.0

import imblearn
OverSampling = RandomOverSampler(sampling_strategy=0.5)

any help appreciated as am not able to understand the possible reason (probably something very simple)


Solution

  • Your import should look like this from imblearn.over_sampling import RandomOverSampler since you're trying to import and directly instantiate a specific class from the imblearn module.