GridSearch over RegressorChain using Scikit-Learn?



我目前正在研究一个多输出回归问题,我试图一次预测多个输出值。我知道有一些标准回归器本身支持此任务。

但是,我想使用RegressorChain并使用GridSearchCV调整回归器链中回归器的超参数。我为此编写了以下代码:

from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVR
from sklearn.model_selection import GridSearchCV
# setup the pipeline
pipeline = Pipeline(steps = [('scale', StandardScaler(with_mean=True, with_std=True)),
('estimator', RegressorChain(SVR())])
# setup the parameter grid
param_grid = {'estimator__estimator__C': [0.1,1,10,100]}           
# setup the grid search
grid = GridSearchCV(pipeline, 
param_grid, 
scoring='neg_mean_squared_error')
# fit model   
grid.fit(X, y)

它尝试了:

param_grid = {'estimator__C': [0.1,1,10,100]}  

和:

param_grid = {'estimator__estimator__C': [0.1,1,10,100]}

但我两次都得到了以下ValueError

值错误:估计器的参数 C 无效 RegressorChain(base_estimator=SVR(C=1.0, cache_size=200, coef0=0.0, 度数=3, ε=0.1, 伽马='auto_deprecated', 内核='RBF', max_iter=-1,收缩=真,tol=0.001,详细=假(, cv=无,顺序=无,random_state=无(。使用estimator.get_params().keys()检查可用参数列表。

有没有人有一个想法,如何正确设置这个管道?谢谢!

正如错误消息所建议的那样,打印RegressorChain(SVR()).get_params()的结果,您将获得:

{
'base_estimator__C': 1.0, 
'base_estimator__cache_size': 200, 
'base_estimator__coef0': 0.0, 
'base_estimator__degree': 3,
...
}

给定您定义的管道,这意味着您应该使用

param_grid = {'estimator__base_estimator__C': [0.1, 1, 10, 100]} 

在网格搜索迭代期间为SVR对象C设置可能的值。

最新更新