jupyter notebook报错:ImportError: cannot import name ‘Imputer‘ from ‘sklearn.preprocessing‘解决方法
生活随笔
收集整理的這篇文章主要介紹了
jupyter notebook报错:ImportError: cannot import name ‘Imputer‘ from ‘sklearn.preprocessing‘解决方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
今天在處理丟失數據時,運行下面代碼報錯
from sklearn.preprocessing import Imputer imputer = Imputer(missing_values = "NaN", strategy = "mean", axis = 0) imputer = imputer.fit(X[ : , 1:3]) X[ : , 1:3] = imputer.transform(X[ : , 1:3])報錯信息如下:
解決方法
在StackOverflow上搜索,結果是
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') imputer = imputer.fit(X[ : , 1:3]) X[ : , 1:3] = imputer.transform(X[ : , 1:3])參考
https://stackoverflow.com/questions/59439096/importerror-cannnot-import-name-imputer-from-sklearn-preprocessing
總結
以上是生活随笔為你收集整理的jupyter notebook报错:ImportError: cannot import name ‘Imputer‘ from ‘sklearn.preprocessing‘解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: anoconda如何切换路径
- 下一篇: jupyter notebook 报错: