我的sklearn之前运行良好,在安装和更新其他几个软件包之后,我无法从sklearn导入任何模型。
版本:
Python 2.7.12
Anaconda 2.4.1(x86_64)
sklearn:0.17.1(降级0.18) 辣味:0.18.1
我尝试的措施:
重启shell --->同样的错误
卸载sklearn,然后重新安装(最新版本为0.18),将其降级为0.17 - >同样的错误
- 安装sklearn并保留版本0.18 - >仍然错误
醇>
我的代码:
from sklearn import svm
错误
Traceback (most recent call last):
File "<ipython-input-1-fe795c4388c4>", line 3, in <module>
from sklearn import svm
File "//anaconda/lib/python2.7/site-packages/sklearn/svm/__init__.py", line 13, in <module>
from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC, \
File "//anaconda/lib/python2.7/site-packages/sklearn/svm/classes.py", line 4, in <module>
from .base import _fit_liblinear, BaseSVC, BaseLibSVM
File "//anaconda/lib/python2.7/site-packages/sklearn/svm/base.py", line 11, in <module>
from ..preprocessing import LabelEncoder
File "//anaconda/lib/python2.7/site-packages/sklearn/preprocessing/__init__.py", line 8, in <module>
from .data import Binarizer
File "//anaconda/lib/python2.7/site-packages/sklearn/preprocessing/data.py", line 25, in <module>
from ..utils.sparsefuncs import (inplace_column_scale,
ImportError: cannot import name inplace_column_scale
除了svm之外,当我导入tree,linear_model时,会发生同样的事情。
from sklearn.models import linear_model
错误:
Traceback (most recent call last):
File "<ipython-input-3-540f6792b379>", line 1, in <module>
from sklearn.models import linear_model
ImportError: No module named models
代码:
from sklearn import tree
错误: 回溯(最近一次调用最后一次):
File "<ipython-input-4-fcc6e7d2ee3e>", line 1, in <module>
from sklearn import tree
File "//anaconda/lib/python2.7/site-packages/sklearn/tree/__init__.py", line 6, in <module>
from .tree import DecisionTreeClassifier
File "//anaconda/lib/python2.7/site-packages/sklearn/tree/tree.py", line 30, in <module>
from ..feature_selection.from_model import _LearntSelectorMixin
File "//anaconda/lib/python2.7/site-packages/sklearn/feature_selection/__init__.py", line 7, in <module>
from .univariate_selection import chi2
File "//anaconda/lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.py", line 15, in <module>
from ..preprocessing import LabelBinarizer
File "//anaconda/lib/python2.7/site-packages/sklearn/preprocessing/__init__.py", line 8, in <module>
from .data import Binarizer
File "//anaconda/lib/python2.7/site-packages/sklearn/preprocessing/data.py", line 25, in <module>
from ..utils.sparsefuncs import (inplace_column_scale,
ImportError: cannot import name inplace_column_scale
答案 0 :(得分:1)
要解决该错误:
ImportError: cannot import name 'OrdinalEnconder' from 'sklearn.preprocessing'
(C:\ProgramData\Anaconda3\lib\site-packages\sklearn\preprocessing\__init__.py)
您需要转到路径“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ sklearn \ preprocessing”,并检查python文件__init__.py
中的OneLabelEncoder的名称。名称可以是LabelEncoder或其他名称。您需要导入具有相同名称的模块。
以下屏幕截图应有助于您更好地理解这一点:
答案 1 :(得分:0)
在您的终端中尝试:
conda install -c anaconda scikit-learn=0.18.1
如果不起作用,请转到您的终端并尝试:
conda update anaconda
更新完成后,再次尝试第一位代码 希望它有效
答案 2 :(得分:0)
请看这个问题。 ImportError: cannot import name inplace_column_scale
我认为你面临同样的问题。有几种方法可以解决它。
对于 windows。删除python27 \ Lib \ site-packages \ sklearn \ utils \ sparsefuncs.pyd。
对于 mac和linux ,请删除/usr/local/lib/python2.7/site-packages/sklearn/utils/sparsefuncs.so。
如果您使用 anaconda ,请删除anaconda / lib / python2.7 / site-packages / sklearn / utils / sparsefun cs.so
重新安装sklearn。 点击卸载scikit-learn pip install scikit-learn