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

GradientBoostingClassifier管道配合RandomizedSearchCV参数配置报错排查

问题排查与解决

错误原因

你代码里的核心问题是调参字典的参数前缀和Pipeline中分类器的命名不匹配:
在Pipeline定义里,你把GradientBoostingClassifier命名为gb(steps=[("scaler",scaler), ("gb", GradientBoostingClassifier(...))]),但调参参数用了clasificador__作为前缀,这导致RandomizedSearchCV无法识别该参数,所以抛出报错。

修正后的代码

把调参字典里所有的clasificador__替换成gb__即可,同时补充完整必要的导入:

import numpy as np
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.pipeline import Pipeline
from sklearn.model_selection import RandomizedSearchCV

scaler = StandardScaler()

pipe_gb = Pipeline(steps=[("scaler",scaler), ("gb", GradientBoostingClassifier(random_state=42))])

params_gb = [
    {'gb__learning_rate': np.arange(0.01, 1, 0.02), 'gb__n_estimators': np.arange(50,100, 2),
     "gb__max_depth": [1, 2, 3, 5], 'gb__loss': ['log_loss', 'exponential'], 
     'gb__max_features': ['auto', 'sqrt', 'log2']}
]

gb = RandomizedSearchCV(estimator=pipe_gb, 
                  param_distributions = params_gb, 
                  scoring='accuracy', 
                  refit=True,
                  cv=5,
                  n_jobs=-1)

gb = gb.fit(X_train, y_train)

额外提示

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

print(pipe_gb.get_params().keys())

输出结果里会包含类似gb__learning_rate、gb__n_estimators这类正确的参数名格式。

内容的提问来源于stack exchange,提问作者Emi Colombo

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 06:05:19