56

Trying to import Imputer from sklearn.preprocessing,

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)"

Ilya
  • 1
  • 5
  • 18
Vikram
  • 714
  • 1
  • 5
  • 10

1 Answers1

133

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

from sklearn.impute import SimpleImputer
import numpy as np

imputer = SimpleImputer(missing_values=np.nan, strategy='mean')

pip install scikit-learn==0.20.4 or conda install scikit-learn=0.20.4 are not a good options because scikit-learn==0.20.4 is more than 3 years out of date.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
deramko
  • 2,807
  • 1
  • 18
  • 27