系统win10 64位,python版本3.7.4。
全局环境下,在我输入下载sklearn包的代码后,显示结果如下,包已经安装:
pip install sklearn
Requirement already satisfied: sklearn in e:\python\lib\site-packages (0.0)
Requirement already satisfied: scikit-learn in e:\python\lib\site-packages (from sklearn) (0.22)
Requirement already satisfied: numpy>=1.11.0 in e:\python\lib\site-packages (from scikit-learn->sklearn) (1.17.4)
Requirement already satisfied: scipy>=0.17.0 in e:\python\lib\site-packages (from scikit-learn->sklearn) (1.3.3)
Requirement already satisfied: joblib>=0.11 in e:\python\lib\site-packages (from scikit-learn->sklearn) (0.14.1)
然而在使用sklearn中的Imputer函数时,会出现报错:
>>> import numpy as np
>>> import sklearn
>>> from sklearn import preprocessing
>>> from sklearn.preprocessing import Imputer
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing' (E:\python\lib\site-packages\sklearn\preprocessing\__init__.py)
利用dir()查看包内的函数,发现没有Imputer:
>>> dir(sklearn.preprocessing)
['Binarizer', 'FunctionTransformer', 'KBinsDiscretizer', 'KernelCenterer', 'LabelBinarizer', 'LabelEncoder', 'MaxAbsScaler', 'MinMaxScaler', 'MultiLabelBinarizer', 'Normalizer', 'OneHotEncoder', 'OrdinalEncoder', 'PolynomialFeatures', 'PowerTransformer', 'QuantileTransformer', 'RobustScaler', 'StandardScaler', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_csr_polynomial_expansion', '_data', '_discretization', '_encoders', '_function_transformer', '_label', 'add_dummy_feature', 'binarize', 'label_binarize', 'maxabs_scale', 'minmax_scale', 'normalize', 'power_transform', 'quantile_transform', 'robust_scale', 'scale']
但是在conda的base环境下,陆续安装numpy、scipy、matplotlib后,安装
scikit-learn包,就可以使用这个函数了。
我寻找了很久的解决方案,网上说的路径和Imputer相同的情况没有发生,请问大佬们这究竟是怎么回事儿啊