Search code examples
pythonmachine-learninganacondapython-importimblearn

Problem with importing RUSBoostClassifier from imblearn


I have gotten stuck with importing RUSBoostClassifier following this example

from imblearn.ensemble import RUSBoostClassifier

I receive the following error:

ImportError                               Traceback (most recent call last)
<ipython-input-12-d0ff5157a81a> in <module>
----> 1 from imblearn.ensemble import RUSBoostClassifier
  2 from sklearn.datasets import make_classification
  3 
  4 X, y = make_classification(n_samples=1000, n_classes=3,
  5                            n_informative=4, weights=[0.2, 0.3, 0.5],

ImportError: cannot import name 'RUSBoostClassifier'

I do not understand why! I can easily use other modules from imblearn such as

from imblearn.under_sampling import RandomUnderSampler

or

from imblearn.over_sampling import SMOTE 

I use Jupyter notebook, the Python version is 3.6.6. I have updated sklearn package and reinstall imblearn package following this link.

Does anyone have any idea to solve this problem? Or have an idea to use directly this class (source code) in a code?


Solution

  • The problem was the version of imblearn package. New modules of imblearn such as RUSBoostClassifier or BalancedRandomForestClassifier are supported in version 0.4.3. The version of imblearn package can be checked with !pip list (thanks to @desertnaut). If you are using an old version, remove it completely (reinstalling the imblearn was not actually helpful for me). After that follow this instruction and install it in agin. In this case the latest version of imblearn will be added to your anaconda environment.