尝试导入 imputer 模块时出错

error while trying to import the imputer module

我在尝试导入 imputer 模块时遇到此错误

from sklearn.preprocessing import Imputer

错误:

ImportError                               Traceback (most recent call last)
<ipython-input-10-40d42fb5b303> in <module>
      1 # Import the Imputer module
----> 2 from sklearn.preprocessing import Imputer
      3 from sklearn.svm import SVC
      4 
      5 # Setup the Imputation transformer: imp

ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing' (C:\Users\MOSTAFA\anaconda3\lib\site-packages\sklearn\preprocessing\__init__.py)

https://scikit-learn.org/stable/modules/generated/sklearn.impute.SimpleImputer.html

New in version 0.20: SimpleImputer replaces the previous sklearn.preprocessing.Imputer estimator which is now removed.

因此,从 sklearn 0.20 开始,您需要改用 SimpleImputer。

尝试:from sklearn.impute import SimpleImputer