【发布时间】:2021-07-30 19:30:53
【问题描述】:
Scikit-learn 的 Iterative Imputer 可以以 round-robin 方式估算缺失值。为了评估其与其他传统回归器的性能,可以构建一个简单的管道并从 cross_val_score 获取评分指标。问题是Iterative Imputer没有根据错误的“预测”方法:
AttributeError: 'IterativeImputer' object has no attribute 'predict'
查看尝试实现的目标的最小示例:
# import libraries
import pandas as pd
from sklearn.experimental import enable_iterative_imputer
from sklearn.impute import IterativeImputer
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import cross_val_score
from sklearn.pipeline import Pipeline
# define scaler, model and pipeline
scaler = StandardScaler() # use any scaler
imputer = IterativeImputer() # with any estimator, default = BayesianRidge()
pipeline = Pipeline(steps=[('s', scaler), ('i', imputer)])
train, test = df.values, df['A'].values
scores = cross_val_score(pipeline, train, test, cv=10, scoring='r2')
print(scores)
存在哪些可能的解决方案?如果需要自定义包装器,应如何编写以包含“预测”方法?
【问题讨论】:
-
总是将完整的错误消息(从单词“Traceback”开始)作为文本(不是截图,不是链接到外部门户)有问题(不是评论)。还有其他有用的信息。
-
您必须将
model添加为Pipeline中的最后一个元素。而model将有predict
标签: python machine-learning scikit-learn missing-data imputation