如果param_grid中的kernel =线性,如何选择线性SVC而不是SVC?
我有以下方法来创建GRID_CV_OBJECT。其中hyperpam_grid = {“ c”:c,“ kernel”:kernel,“ gamma”:gamma:gamma,“ geger”:deg}
。
grid_cv_object = GridSearchCV(
estimator = SVC(cache_size=cache_size),
param_grid = hyperpam_grid,
cv = cv_splits,
scoring = make_scorer(matthews_corrcoef), # a callable returning single value, binary and multiclass labels are supported
n_jobs = -1, # use all processors
verbose = 10,
refit = refit
)
这里的内核可以是('rbf','linear','poly')
。
如何为“线性”内核执行线性选择?由于这嵌入到hyperparam_grid
中,因此我不确定如何创建这种“ Switch”。
如果可能的话,我只是不想拥有2个单独的grid_cv_objects。
I have the following way to create the grid_cv_object. Where hyperpam_grid={"C":c, "kernel":kernel, "gamma":gamma, "degree":degree}
.
grid_cv_object = GridSearchCV(
estimator = SVC(cache_size=cache_size),
param_grid = hyperpam_grid,
cv = cv_splits,
scoring = make_scorer(matthews_corrcoef), # a callable returning single value, binary and multiclass labels are supported
n_jobs = -1, # use all processors
verbose = 10,
refit = refit
)
Here kernel can be ('rbf', 'linear', 'poly')
for example.
How can I enforce the selection of LinearSVC for the 'linear' kernel? Since this is embedded in hyperparam_grid
I'm not sure how to create this sort of "switch".
I just don't want to have 2 separate grid_cv_objects if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在以下形式的
讨论中制作参数网格:
我们将不同的内核与不同实例的
svc
分开。这样,GridSearchCV
将无法估计,例如,svc(kernel ='poly')
带有不同的gamma
s,这些 s s被忽略。 >'poly',仅针对rbf
。当您要求时,
linearsvc
(实际上任何其他模型),而不是svc(kernel ='Linearear')
,以估算线性SVM。<<<<<<<<<<<<<<<<<<<<< /p>最佳估计器将为
grid.best_estimator_.named_steps ['svm']
。Try making parameter grids in the following form
Discussion:
We separate different kernels with different instances of
SVC
. This way,GridSearchCV
will not estimate, say,SVC(kernel='poly')
with differentgamma
s, which are ignored for'poly'
and are designated only forrbf
.As you request,
LinearSVC
(and in fact any other model), notSVC(kernel='linear')
, is separated to estimate a linear svm.Best estimator will be
grid.best_estimator_.named_steps['svm']
.