ModuleNotFoundError: No module named 'imblearn'

bernando_vialli picture bernando_vialli · May 16, 2018 · Viewed 42.4k times · Source

I tried running the following code:

from imblearn import under_sampling, over_sampling
from imblearn.over_sampling import SMOTE

sm = SMOTE(random_state=12, ratio = 1.0)
x_SMOTE, y_SMOTE = sm.fit_sample(X, y) 

which gives me the error message:

ModuleNotFoundError: No module named 'imblearn'

I have tried installing the imblearn module in multiple ways, they all seem to work (there are no errors given during the installation but when I run the above code, I get an error message).

I tried istalling imblearn using the following suggested in other stackoverflow questions:

pip install -U imbalanced-learn
pip install imblearn
!pip install imblearn
pip install -c glemaitre imbalanced-learn
pip install imblearn==0.0

None of these seem to help... Any ideas? Thank you!

Answer

Ashok Kumar Jayaraman picture Ashok Kumar Jayaraman · Nov 8, 2018

I installed the module named imblearn using anaconda command prompt.

conda install -c conda-forge imbalanced-learn

Then imported the packages

from imblearn import under_sampling, over_sampling
from imblearn.over_sampling import SMOTE

Again, I tried to install imblearn through pip, it works for me.

(base) C:\WINDOWS\system32>pip install -U imbalanced-learn
Requirement already up-to-date: imbalanced-learn in c:\users\ashok\anaconda3\lib\site-packages (0.4.3)
Requirement already satisfied, skipping upgrade: numpy>=1.8.2 in c:\users\ashok\anaconda3\lib\site-packages (from imbalanced-learn) (1.15.3)
Requirement already satisfied, skipping upgrade: scipy>=0.13.3 in c:\users\ashok\anaconda3\lib\site-packages (from imbalanced-learn) (0.19.1)
Requirement already satisfied, skipping upgrade: scikit-learn>=0.20 in c:\users\ashok\anaconda3\lib\site-packages (from imbalanced-learn) (0.20.0)