在学习数据处理,引入包时
from sklearn.preprocessing import Imputer, MinMaxScaler
cannot import name 'Imputer' from 'sklearn.preprocessing' (/Users/sunfeiyang/opt/anaconda3/lib/python3.8/site-packages/sklearn/preprocessing/__init__.py)
无法导入
查看官方文档,关于 imputer部分,发现
新版本0.20以来 SimpleImputer 代替 Imputer
查看自身电脑的 sklearn 系统
import sklearn
print(sklearn.__version__)
Sklearn verion is 0.23.1
显然需要用最新的官方文档的形式
from sklearn.impute import SimpleImputer
example:
import numpy as np
from sklearn.impute import SimpleImputer
imp_mean = SimpleImputer(missing_values=np.nan, strategy='mean')
imp_mean.fit([[7, 2, 3], [4, np.nan, 6], [10, 5, 9]])X = [[np.nan, 2, 3], [4, np.nan, 6], [10, np.nan, 9]]
print(imp_mean.transform(X))
[[ 7. 2. 3. ][ 4. 3.5 6. ][10. 3.5 9. ]]