【问题标题】:GridSearch over RegressorChain using Scikit-Learn?使用 Scikit-Learn 在 RegressorChain 上进行 GridSearch?
【发布时间】:2020-10-24 01:07:21
【问题描述】:

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

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

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

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=None,order=None,random_state=None)。使用estimator.get_params().keys()查看可用参数列表。

有人知道如何正确设置此管道吗?谢谢!

【问题讨论】:

    标签: python scikit-learn regression gridsearchcv


    【解决方案1】:

    如错误信息所示,打印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 设置可能的值。

    【讨论】:

    • 很好,再次感谢您! scikit-learning 的管道命名约定对我来说仍然有点令人困惑,但你的观点完全有道理并且奏效了。
    猜你喜欢
    • 2017-07-10
    • 2018-02-22
    • 2014-11-19
    • 2016-03-17
    • 2015-02-04
    • 2012-12-30
    • 2019-06-29
    • 2017-01-22
    • 2015-09-12
    相关资源
    最近更新 更多