当前位置: 代码迷 >> 综合 >> jupyter 中无法从 sklearn 导入imputer 库( from sklearn.preprocessing import Imputer, MinMaxScaler)
  详细解决方案

jupyter 中无法从 sklearn 导入imputer 库( from sklearn.preprocessing import Imputer, MinMaxScaler)

热度:75   发布时间:2024-02-07 06:27:01.0

在学习数据处理,引入包时

from sklearn.preprocessing import Imputer, MinMaxScaler
cannot import name 'Imputer' from 'sklearn.preprocessing' (/Users/sunfeiyang/opt/anaconda3/lib/python3.8/site-packages/sklearn/preprocessing/__init__.py)

无法导入

查看官方文档,关于 imputer部分,发现

新版本0.20以来 SimpleImputer 代替 Imputer

查看自身电脑的 sklearn 系统

import sklearn
print(sklearn.__version__)
Sklearn verion is 0.23.1

显然需要用最新的官方文档的形式

from sklearn.impute import SimpleImputer

example:

import numpy as np
from sklearn.impute import SimpleImputer
imp_mean = SimpleImputer(missing_values=np.nan, strategy='mean')
imp_mean.fit([[7, 2, 3], [4, np.nan, 6], [10, 5, 9]])X = [[np.nan, 2, 3], [4, np.nan, 6], [10, np.nan, 9]]
print(imp_mean.transform(X))
[[ 7.   2.   3. ][ 4.   3.5  6. ][10.   3.5  9. ]]

 

 

  相关解决方案