如何解决sklearn Stacking Estimator passthrough 跳过预处理并传递原始数据
这里已经讨论过这个问题,但没有评论:https://github.com/scikit-learn/scikit-learn/issues/16473
我在 X 中有一些数值特征和分类特征。分类特征是一种热编码。所以我的管道类似于 sklearn 文档示例:
cat_proc_lin = make_pipeline(
SimpleImputer(missing_values=None,strategy='constant',fill_value='missing'),OneHotEncoder(categories=categories)
)
num_proc_lin = make_pipeline(
SimpleImputer(strategy='mean'),StandardScaler()
)
processor_lin = make_column_transformer(
(cat_proc_lin,cat_cols),(num_proc_lin,num_cols),remainder='passthrough')
lasso_pipeline = make_pipeline(processor_lin,LassoCV())
rf_pipeline = make_pipeline(processor_nlin,RandomForestRegressor(random_state=42))
gradient_pipeline = make_pipeline(
processor_nlin,HistGradientBoostingRegressor(random_state=0))
estimators = [('Random Forest',rf_pipeline),('Lasso',lasso_pipeline),('Gradient Boosting',gradient_pipeline)]
stacking_regressor = StackingRegressor(estimators=estimators,final_estimator=RidgeCV())
但是如果我更改 passthrough=True,它将引发 TypeError,因为 passthrough 给出原始 X 并跳过管道的预处理部分:
/usr/local/lib/python3.6/dist-packages/sklearn/model_selection/_validation.py:536: FitFailedWarning: Estimator fit failed. The score on this train-test partition for these parameters will be set to nan. Details:
ValueError: could not convert string to float: 'RL'
无论如何要让直通包括管道的第一个预处理部分?
我也无法在最终估计器的前面添加预处理管道,因为它会将原始 X 数据帧与最终层预测连接起来,最终层预测是本文顶部的 github 讨论链接中提到的 numpy 数组。我的确切预处理管道有几个自定义转换器,可在 Pandas 数据帧上运行。
感谢您的帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。