jupyter 中无法从 sklearn 导入imputer 库( from sklearn.preprocessing import Imputer, MinMaxScaler)

在学习数据处理,引入包时

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部分,发现

jupyter 中无法从 sklearn 导入imputer 库( from sklearn.preprocessing import Imputer, MinMaxScaler)_第1张图片

新版本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. ]]

 

 

你可能感兴趣的:(sklearn,python,机器学习,数据挖掘)