在ipython笔记本上导入imblearn python包的问题

时间:2016-10-12 20:42:46

标签: python python-2.7 powershell jupyter-notebook imblearn

我使用pip installcondagithub在Windows PowerShell上安装了https://github.com/glemaitre/imbalanced-learn。但是,当我在iPython笔记本上时,我试图使用以下方法导入包:

from unbalanced_dataset import UnderSampler, OverSampler, SMOTE

我收到错误:

ImportError  Traceback (most recent call last) <ipython-input-9-ad6fd7440a05> in <module>()
----> 1 from imbalanced_learn import UnderSampler, OverSampler, SMOTE

ImportError: No module named imbalanced_learn

使用Windows for Python的新手,我是否必须在某个文件夹中安装该软件包?

6 个答案:

答案 0 :(得分:8)

如果它不起作用,也许你需要安装&#34; imblearn&#34;封装

尝试安装:

  • pip:pip install -U imbalanced-learn
  • anaconda:conda install -c glemaitre imbalanced-learn

然后尝试在您的文件中导入库:

  • from imblearn.over_sampling import SMOTE

答案 1 :(得分:3)

试试这个:

from imblearn import under_sampling, over_sampling

要导入SMOTE

from imblearn.over_sampling import SMOTE

或数据集:

from imblearn.datasets import ...

答案 2 :(得分:0)

类型 !pip install imblearn

在jupyter笔记本中。这对我有用。

答案 3 :(得分:0)

我已经尝试了所有这些解决方案,但是没有任何效果,只有对我有用的是更改内核。我在Amazon Sagemaker上运行Jupyter,并将内核从pyhton3更改为pytorch36,它工作得很好。希望对您有帮助

答案 4 :(得分:0)

最终对我有用的是根据Add Virtual Environment to Jupyter Notebook

将虚拟视频放入笔记本

这就是我使用文章中的命令所做的:

$ python3 -m pip install --user ipykernel

# add the virtual environment to Jupyter
$ python3 -m ipykernel install --user --name=venv

# create the virtual env in the working directory
$ python3 -m venv ./venv

# activate the venv
$ source venv/bin/activate

# install the package
(venv) pip install imbalanced-learn

# fire up the notebook
(venv) jupyter notebook

答案 5 :(得分:-1)

pip install -U imbalanced-learn应该有效,但要确保你已经遇到了numpy,scipy和scikit-learn的依赖关系。

Imbalanced-learn 0.3.0 Install Documentation

相关问题