运行提示错误 ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing' 解决办法

(前面省略)
from sklearn.preprocessing import Imputer as SimpleImputer
# from sklearn.impute import SimpleImputer

imputer = SimpleImputer(strategy = 'median')

#使用fit()方法将imputer实例适配到训练集
housing_num = housing.drop('ocean_proximity', axis =1)

imputer.fit(housing_num)

当运行上面的代码时,提示这样报错ImportError: cannot import name ‘Imputer’ from ‘sklearn.preprocessing’
首先检查自己的电脑是否pip install sklearn,如果已经安装,那么把上面的导包程序修改为

from sklearn.impute import SimpleImputer

问题就得到解决
运行提示错误 ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing' 解决办法_第1张图片

你可能感兴趣的:(运行提示错误 ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing' 解决办法)