简体   繁体   English

没有名为“sklearn.neighbors._base”的模块

[英]No module named 'sklearn.neighbors._base'

I have recently installed imblearn package in jupyter using我最近在 jupyter 中安装了 imblearn 包

!pip show imbalanced-learn

But I am not able to import this package.但我无法导入这个包。

from tensorflow.keras import backend
from imblearn.over_sampling import SMOTE

I get the following error我收到以下错误

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-20-f19c5a0e54af> in <module>
      1 # from sklearn.utils import resample
      2 from tensorflow.keras import backend
----> 3 from imblearn.over_sampling import SMOTE
      4 
      5 

~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/__init__.py in <module>
     32     Module which allowing to create pipeline with scikit-learn estimators.
     33 """
---> 34 from . import combine
     35 from . import ensemble
     36 from . import exceptions

~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/combine/__init__.py in <module>
      3 """
      4 
----> 5 from ._smote_enn import SMOTEENN
      6 from ._smote_tomek import SMOTETomek
      7 

~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/combine/_smote_enn.py in <module>
      8 from sklearn.utils import check_X_y
      9 
---> 10 from ..base import BaseSampler
     11 from ..over_sampling import SMOTE
     12 from ..over_sampling.base import BaseOverSampler

~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/base.py in <module>
     14 from sklearn.utils.multiclass import check_classification_targets
     15 
---> 16 from .utils import check_sampling_strategy, check_target_type
     17 
     18 

~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/utils/__init__.py in <module>
      5 from ._docstring import Substitution
      6 
----> 7 from ._validation import check_neighbors_object
      8 from ._validation import check_target_type
      9 from ._validation import check_sampling_strategy

~/.virtualenvs/p3/lib/python3.6/site-packages/imblearn/utils/_validation.py in <module>
     11 
     12 from sklearn.base import clone
---> 13 from sklearn.neighbors._base import KNeighborsMixin
     14 from sklearn.neighbors import NearestNeighbors
     15 from sklearn.utils.multiclass import type_of_target

ModuleNotFoundError: No module named 'sklearn.neighbors._base'

Other packages in the environment环境中的其他包

numpy==1.16.2
pandas==0.24.2
paramiko==2.1.1
matplotlib==2.2.4
scikit-learn==0.22.1
Keras==2.2.4
tensorflow==1.12.0
tensorboard==1.12.0
tensorflow-hub==0.4.0
xlrd==1.2.0
flask==1.0.2
wtforms==2.2.1
bs4==0.0.1
gensim==3.8.1
spacy==2.2.3
nltk==3.4.5 
wordcloud==1.6.0
pymongo==3.10.1    
imbalanced-learn==0.6.1

I checked the sklearn package, it contains base module, not _base.我检查了 sklearn 包,它包含基本模块,而不是 _base。 But modifying it may not be the right solution.但是修改它可能不是正确的解决方案。 Any other solution to fix this issue.解决此问题的任何其他解决方案。

Previous sklearn.neighbors.base has been renamed to sklearn.neighbors._base in version 0.22.1 .以前的sklearn.neighbors.base已在sklearn.neighbors._base 版本中重命名为sklearn.neighbors._base
You have probably a version of scikit-learn older than that.您可能有一个比这更旧的 scikit-learn 版本。 Installing the latest release solves the problem:安装最新版本解决了这个问题:

pip install -U scikit-learn

or或者

pip install scikit-learn==0.22.1

If in case you want to persist with the latest version of scikit-learn, add the following code to your script or execute the following code in your environment before installing imblearn如果您想坚持使用最新版本的 scikit-learn,请在安装 imblearn 之前将以下代码添加到您的脚本或在您的环境中执行以下代码

import sklearn.neighbors._base
sys.modules['sklearn.neighbors.base'] = sklearn.neighbors._base

This has to be after这必须在

pip install sklearn

or in a notebook environment:或在笔记本环境中:

!pip install sklearn

This problem stems from the fact that certain modules are named with an underscore in the newer scikit-learn releases这个问题源于这样一个事实,即某些模块在较新的 scikit-learn 版本中用下划线命名

I had a similar problem trying to import SMOTE from imblearn.over_sampling and my version of scikit-learn was up to date (0.24.1).我在尝试从imblearn.over_sampling导入imblearn.over_sampling遇到了类似的问题,我的 scikit-learn 版本是最新的 (0.24.1)。 What worked for me was:对我有用的是:

First I downgraded my scikit learn version to 0.22.1 using首先,我使用

 pip install scikit-learn==0.22.1

Next, I updated the imbalanced-learn package using:接下来,我使用以下方法更新了不平衡学习包:

pip install -U imbalanced-learn

That uninstalled scikit-learn-0.22.1, installed the updated version (scikit-learn-0.24.1), and updated the imbalanced-learn package.卸载了 scikit-learn-0.22.1,安装了更新版本 (scikit-learn-0.24.1),并更新了不平衡学习包。 Everything worked fine thereafter.此后一切正常。

If it is in a particular env, you must copy the _base file or base file to the env from package file.如果它在特定的 env 中,则必须将_base文件或base文件从包文件复制到 env。

I had the same problem in my tensorflow env.我在我的 tensorflow 环境中遇到了同样的问题。 I just copied _base and base file to my tensorflow env and worked.我只是将_basebase文件复制到我的 tensorflow 环境中并工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 导入错误:无法从“sklearn.neighbors._base”导入名称“克隆” - ImportError: cannot import name 'clone' from 'sklearn.neighbors._base 在我可以接受的所有建议之后,没有名为“sklearn.neighbors.base”的模块仍然存在 - No module named 'sklearn.neighbors.base' still existed after all the suggestions what I can take ModuleNotFoundError:没有名为“sklearn.neighbors._dist_metrics”的模块 - ModuleNotFoundError: No module named 'sklearn.neighbors._dist_metrics' ModuleNotFoundError:PyInstaller 没有名为“sklearn.neighbors._partition_nodes”的模块 - ModuleNotFoundError: No module named 'sklearn.neighbors._partition_nodes' with PyInstaller 没有名为“sklearn.linear_model.base”的模块 - No module named 'sklearn.linear_model.base' Pyinstaller和sklearn.ensemble:&#39;ModuleNotFoundError:没有名为&#39;sklearn.neighbors.quad_tree&#39;的模块[2760]&#39; - Pyinstaller and sklearn.ensemble: 'ModuleNotFoundError: No module named 'sklearn.neighbors.quad_tree' [2760]' ModuleNotFoundError:没有名为“sklearn.linear_model._base”的模块 - ModuleNotFoundError: No module named 'sklearn.linear_model._base' ModuleNotFoundError:没有名为“sklearn.linear_model.base”的模块错误 PYTHON - ModuleNotFoundError: No module named 'sklearn.linear_model.base' ERROR PYTHON ModuleNotFoundError:没有名为“sklearn.linear_model.base”的模块 - ModuleNotFoundError: No module named 'sklearn.linear_model.base' 没有名为“ sklearn”的模块 - No Module named “sklearn”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM