Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannnot import name 'Imputer' from 'sklearn.preprocessing'

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 

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

like image 597
Vikram Avatar asked Dec 21 '19 19:12

Vikram


People also ask

What is Imputer in Sklearn?

The imputation strategy. If “mean”, then replace missing values using the mean along the axis. If “median”, then replace missing values using the median along the axis. If “most_frequent”, then replace missing using the most frequent value along the axis.

What is Imputer fit python?

You use an Imputer to handle missing data in your dataset. Imputer gives you easy methods to replace NaNs and blanks with something like the mean of the column or even median. But before it can replace these values, it has to calculate the value that will be used to replace blanks.


1 Answers

from sklearn.preprocessing import Imputer was deprecated with scikit-learn v0.20.4 and removed as of v0.22.2.

from sklearn.impute import SimpleImputer imputer = SimpleImputer(missing_values=np.nan, strategy='mean') 
like image 100
deramko Avatar answered Sep 23 '22 03:09

deramko