本文介绍了导入错误:无法从“sklearn.preprocessing"导入名称“Imputer"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试从 sklearn 导入 Imputer,

Trying to import Imputer from sklearn,

import pandas as pd
dataset = pd.read_csv('Data.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 3].values

#PART WHERE ERROR OCCURS:-
from sklearn.preprocessing import Imputer

显示ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing' (/home/codeknight13/anaconda3/lib/python3.7/site-packages/sklearn/preprocessing/__init__.py)"

Shows "ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing' (/home/codeknight13/anaconda3/lib/python3.7/site-packages/sklearn/preprocessing/__init__.py)"

推荐答案

from sklearn.preprocessing import Imputer 已被 scikit-learn v0.20.4 弃用并从v0.22.2.

from sklearn.impute import SimpleImputer
imputer = SimpleImputer(missing_values=np.nan, strategy='mean')

这篇关于导入错误:无法从“sklearn.preprocessing"导入名称“Imputer"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 20:33