簡體   English   中英

使用 Scikit-Learn 在 RegressorChain 上進行 GridSearch?

[英]GridSearch over RegressorChain using Scikit-Learn?

我目前正在研究一個多輸出回歸問題,我試圖一次預測多個 output 值。 我知道有標准的回歸器本身就支持這項任務。

但是,我想使用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, degree=3, epsilon=0.1, gamma='auto_deprecated', kernel='rbf', max_iter=-1,收縮=True,tol=0.001,詳細=False),cv=None,order=None,random_state=None)。 使用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 object 的C設置可能的值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM