GridSearchCV 是否使用 rbf 内核和不同程度计算 SVC?
Is GridSearchCV computing SVC with rbf kernel and different degrees?
我正在 运行宁 GridSearchCV
与 OneVsRestClasssifer
使用 SVC
作为估算器。这是我的 Pipeline
和 GridSearchCV
参数的方面:
pipeline = Pipeline([
('clf', OneVsRestClassifier(SVC(verbose=True), n_jobs=1)),
])
parameters = {
"clf__estimator__C": [0.1, 1],
"clf__estimator__kernel": ['poly', 'rbf'],
"clf__estimator__degree": [2, 3],
}
grid_search_tune = GridSearchCV(pipeline, parameters, cv=2, n_jobs=8, verbose=10)
grid_search_tune.fit(train_x, train_y)
根据 SVC 的文档,degree
参数仅供 poly
内核使用:
http://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html
degree : int, optional (default=3)
Degree of the polynomial kernel
function (‘poly’). Ignored by all other kernels.
但是当我看到我的 GridSearchCV
的输出时,它似乎正在为每个 SVC
配置计算不同的 运行,具有 rbf
内核和不同的值degree
参数。
[CV] clf__estimator__kernel=poly, clf__estimator__C=0.1, clf__estimator__degree=2
[CV] clf__estimator__kernel=poly, clf__estimator__C=0.1, clf__estimator__degree=2
[CV] clf__estimator__kernel=rbf, clf__estimator__C=0.1, clf__estimator__degree=2
[CV] clf__estimator__kernel=rbf, clf__estimator__C=0.1, clf__estimator__degree=2
[CV] clf__estimator__kernel=poly, clf__estimator__C=0.1, clf__estimator__degree=3
[CV] clf__estimator__kernel=poly, clf__estimator__C=0.1, clf__estimator__degree=3
[CV] clf__estimator__kernel=rbf, clf__estimator__C=0.1, clf__estimator__degree=3
[CV] clf__estimator__kernel=rbf, clf__estimator__C=0.1, clf__estimator__degree=3
当内核设置为 rbf
时,是否应该忽略度的所有值?
这里显示的输出只是 GridSearchCV
传递给内部估计器的参数的不同组合,即 SVC
。但是否使用它们取决于SVC
。在这种情况下,SVC
不会抛出任何错误,但也不会使用 degree
。您应该打印所有您怀疑的组合的分数。他们应该是平等的。这将告诉您 degree
参数未使用。
注意:确保设置 GridSearchCV
的 random_state
以复制测试。
说明:
GridSearchCV 的工作就是将参数、训练数据传递给估计器进行拟合,然后使用测试数据进行评分,并得出最佳分数的参数组合。
当将不兼容的参数组合传递给估算器时,它取决于实现,是忽略参数还是为其引发错误。
例如。 LogisticRegression中有两个参数:
penalty : str, ‘l1’ or ‘l2’, default: ‘l2’
Used to specify the norm used in the penalization.
solver : {‘newton-cg’, ‘lbfgs’, ‘liblinear’, ‘sag’}, default: ‘liblinear’.
Algorithm to use in the optimization problem.
‘newton-cg’, ‘lbfgs’ and ‘sag’ only handle L2 penalty.
如您所见,如果我将 l1
惩罚与 newton-cg
求解器一起使用,则会导致不兼容。因此,估计器可能会选择完全忽略惩罚参数或抛出错误。在这种情况下,它会引发错误。
我正在 运行宁 GridSearchCV
与 OneVsRestClasssifer
使用 SVC
作为估算器。这是我的 Pipeline
和 GridSearchCV
参数的方面:
pipeline = Pipeline([
('clf', OneVsRestClassifier(SVC(verbose=True), n_jobs=1)),
])
parameters = {
"clf__estimator__C": [0.1, 1],
"clf__estimator__kernel": ['poly', 'rbf'],
"clf__estimator__degree": [2, 3],
}
grid_search_tune = GridSearchCV(pipeline, parameters, cv=2, n_jobs=8, verbose=10)
grid_search_tune.fit(train_x, train_y)
根据 SVC 的文档,degree
参数仅供 poly
内核使用:
http://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html
degree : int, optional (default=3)
Degree of the polynomial kernel function (‘poly’). Ignored by all other kernels.
但是当我看到我的 GridSearchCV
的输出时,它似乎正在为每个 SVC
配置计算不同的 运行,具有 rbf
内核和不同的值degree
参数。
[CV] clf__estimator__kernel=poly, clf__estimator__C=0.1, clf__estimator__degree=2
[CV] clf__estimator__kernel=poly, clf__estimator__C=0.1, clf__estimator__degree=2
[CV] clf__estimator__kernel=rbf, clf__estimator__C=0.1, clf__estimator__degree=2
[CV] clf__estimator__kernel=rbf, clf__estimator__C=0.1, clf__estimator__degree=2
[CV] clf__estimator__kernel=poly, clf__estimator__C=0.1, clf__estimator__degree=3
[CV] clf__estimator__kernel=poly, clf__estimator__C=0.1, clf__estimator__degree=3
[CV] clf__estimator__kernel=rbf, clf__estimator__C=0.1, clf__estimator__degree=3
[CV] clf__estimator__kernel=rbf, clf__estimator__C=0.1, clf__estimator__degree=3
当内核设置为 rbf
时,是否应该忽略度的所有值?
这里显示的输出只是 GridSearchCV
传递给内部估计器的参数的不同组合,即 SVC
。但是否使用它们取决于SVC
。在这种情况下,SVC
不会抛出任何错误,但也不会使用 degree
。您应该打印所有您怀疑的组合的分数。他们应该是平等的。这将告诉您 degree
参数未使用。
注意:确保设置 GridSearchCV
的 random_state
以复制测试。
说明: GridSearchCV 的工作就是将参数、训练数据传递给估计器进行拟合,然后使用测试数据进行评分,并得出最佳分数的参数组合。
当将不兼容的参数组合传递给估算器时,它取决于实现,是忽略参数还是为其引发错误。
例如。 LogisticRegression中有两个参数:
penalty : str, ‘l1’ or ‘l2’, default: ‘l2’ Used to specify the norm used in the penalization. solver : {‘newton-cg’, ‘lbfgs’, ‘liblinear’, ‘sag’}, default: ‘liblinear’. Algorithm to use in the optimization problem. ‘newton-cg’, ‘lbfgs’ and ‘sag’ only handle L2 penalty.
如您所见,如果我将 l1
惩罚与 newton-cg
求解器一起使用,则会导致不兼容。因此,估计器可能会选择完全忽略惩罚参数或抛出错误。在这种情况下,它会引发错误。