创建一个imputer实例, 指定你要用属性中的中位数替代该属性的缺失值,再使用fit()方法将imputer实例适配到训练集,实现代码如下:
from sklearn.impute import SimpleImputer
imputer = SimpleImputer(strategy='median')
imputer.fit(housing)
运行结果如下:
ValueError: Cannot use median strategy with non-numeric data:
could not convert string to 

发布评论