我尝试运行以下代码:

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)

这给了我错误信息:
ModuleNotFoundError: No module named 'imblearn'

我尝试以多种方式安装imblearn模块,它们似乎都可以工作(安装过程中未出现任何错误,但是当我运行上述代码时,出现错误消息)。

我使用其他stackoverflow问题中建议的以下内容尝试了istalling imblearn:
pip install -U imbalanced-learn
pip install imblearn
!pip install imblearn
pip install -c glemaitre imbalanced-learn
pip install imblearn==0.0

这些似乎都无济于事...有什么想法吗?谢谢!

最佳答案

我使用anaconda命令提示符安装了名为imblearn的模块。

conda install -c conda-forge imbalanced-learn

然后导入包
from imblearn import under_sampling, over_sampling
from imblearn.over_sampling import SMOTE

同样,我尝试通过pip安装imblearn,它对我有用。
(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)

关于python-3.x - ModuleNotFoundError : No module named 'imblearn' ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50376990/

10-10 05:54