You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

解决GridSearch调优Pipeline中SelectFromModel嵌入分类器的参数报错

问题解决:GridSearch调参时SelectFromModel嵌套estimator的参数命名错误

错误原因

你在param_grid里对SelectFromModel中嵌套的ExtraTreesClassifier参数命名错误。sklearn中,Pipeline/ColumnTransformer里嵌套组件的参数,需要用父组件名__子参数名的格式,对于SelectFromModel里的estimator,正确的前缀是estimator__,而不是直接写类名ExtraTreesClassifier。

解决方案

修改param_grid中对应参数的命名:
把原来的:

'preprocessor__cat__Categorical_Selector__ExtraTreesClassifier__n_estimators': [100, 200, 300]

替换为:

'preprocessor__cat__Categorical_Selector__estimator__n_estimators': [100, 200, 300]

如果需要调整ExtraTreesClassifier的其他参数(比如criterion),同样遵循这个格式,比如:

'preprocessor__cat__Categorical_Selector__estimator__criterion': ['gini', 'entropy']

验证参数名(可选)

如果不确定参数名,可以运行以下代码查看SelectFromModel的所有可用参数:

print(pipe.named_steps['preprocessor'].named_transformers_['cat'].named_steps['Categorical_Selector'].get_params().keys())

输出里会包含类似estimator__n_estimators、estimator__criterion这样的有效参数名。

修改后的完整param_grid示例

param_grid = {
    'preprocessor__num__PCA__n_components': [0.99, 0.97, 0.95, 0.93],
    'preprocessor__cat__Categorical_Selector__estimator__n_estimators': [100, 200, 300],
    'RandomForest__bootstrap': [False],
    'RandomForest__criterion': ['entropy'],
    'RandomForest__max_depth': range(100, 300, 100),
    'RandomForest__max_features': ['auto'],
    'RandomForest__min_samples_leaf': [1, 3],
    'RandomForest__min_samples_split': range(1, 10, 2),
    'RandomForest__n_estimators': range(200, 1000, 100)
}

内容的提问来源于stack exchange,提问作者Mahyar Arani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 19:10:32