【问题标题】:Problems importing imblearn python package on ipython notebook在 ipython notebook 上导入 imblearn python 包的问题
【发布时间】:2017-02-21 19:28:04
【问题描述】:

我使用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,我必须将包安装在某个文件夹中吗?

【问题讨论】:

  • 嗨,你有没有让这个工作,如果有,怎么做?我正在尝试按照答案给出的说明来了解是否有用。

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


【解决方案1】:

最终对我有用的是根据Add Virtual Environment to Jupyter Notebook将venv放入笔记本中

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

$ 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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      类型 !pip 安装 imblearn

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

      【讨论】:

        【解决方案4】:

        pip install -U imbalanced-learn 应该可以工作,但请确保您已满足 numpy、scipy 和 scikit-learn 的依赖项。

        Imbalanced-learn 0.3.0 Install Documentation

        【讨论】:

          【解决方案5】:

          如果它不起作用,也许你需要安装“imblearn”包。

          尝试安装:

          • 点子:pip install -U imbalanced-learn
          • 蟒蛇:conda install -c glemaitre imbalanced-learn

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

          • from imblearn.over_sampling import SMOTE

          【讨论】:

          • 嗨,我已经采取了您建议的那些步骤,但仍然无法正常工作。有什么想法吗?
          • “pip”解决方案在 Jupyter 笔记本中有效。谢谢。
          【解决方案6】:

          试试这个:

          from imblearn import under_sampling, over_sampling
          

          为了导入SMOTE:

          from imblearn.over_sampling import SMOTE
          

          或数据集:

          from imblearn.datasets import ...
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2020-10-28
            • 2019-03-25
            • 2019-04-16
            • 1970-01-01
            • 1970-01-01
            • 2016-05-17
            • 2019-03-23
            • 1970-01-01
            相关资源
            最近更新 更多