python - 使用 Scikit-Learn 在 RegressorChain 上进行 GridSearch?
问题描述
我目前正在研究一个多输出回归问题,我试图一次预测多个输出值。我知道有标准的回归器本身就支持这项任务。
但是,我想使用 aRegressorChain
并调整 RegressorChain 中 Regressor 的超参数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
:
ValueError: Invalid parameter C for estimator 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]}
在网格搜索的迭代过程中C
为您的对象设置可能的值。SVR
推荐阅读
- javascript - GraphQL Node.js:确定查询中使用的类型
- jquery - ajax-datatables-rails 在数据表中搜索时出现问题
- java - 在 HikariPool 中关闭连接
- java - 如何限制排列的生成?(在 Java 中)
- java - 使用 Xmx 操作 JVM 的内存限制
- javascript - Promise 本身是否有一个时间,如果它在特定的时间段内从未解决,它最终会“拒绝”自己?
- reactjs - React Router 不会在子组件的 Route 上渲染新组件
- node.js - vuejs 和 vuex || 从 v-for 中查找数据以获取另一个数据
- php - 如何使用 php 在 var 中获取对象
- android - Kotlin:如何将图像从 Internet 保存到内部存储