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

前端 未结 3 752
灰色年华
灰色年华 2020-12-30 01:33

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
         


        
相关标签:
3条回答
  • 2020-12-30 02:11

    Try this:

    from sklearn.impute import SimpleImputer

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

    imr = imr.fit(df.values)

    imputed_data = imr.transform(df.values)

    print (imputed_data)

    Note: New changes are in boldface for your quick reference.

    0 讨论(0)
  • 2020-12-30 02:31

    The class is deprecated, use

    from sklearn.impute import SimpleImputer
    imputer = SimpleImputer(missing_values=np.nan, strategy='mean')
    
    0 讨论(0)
  • 2020-12-30 02:34

    After the version scikit-learn SimpleImputer/Imputer has been changed its location from sklearn.preprocessing to package sklearn.impute.

    So, kindly use the below line of code to import.

    from sklearn.impute import SimpleImputer

    Thank you!

    0 讨论(0)
提交回复
热议问题