1
$\begingroup$

I'm running a GridSearchCV with a OneVsRestClasssifer using SVC as an estimator. This is the aspect of my Pipeline and GridSearchCV parameters:

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)

According to the documentation of SVC the degree parameter is only used by the poly kernel:

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.

but when I see the output of my GridSearchCV it seems it's computing a different run for each SVC configuration with a rbf kernel and different values for the degree parameter.

[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

Shouldn't all values of degree be ignored, when the kernel is set to rbf?

$\endgroup$

1 Answer 1

3
$\begingroup$

From what I understand, you'll be able to pass different values of degree even when you're using kernels that are not the polynomial kernel, just that it will not be used. I believe the score will come out to be similar for the other kernels even with different degrees. Will you be able to confirm this?

To avoid additional computation time due to redundant searches, you can fine tune the GridSearchCV by specifying two grids. Try out the below code and passing it into the param_grid argument.

param_grid = [
  {'C': [1, 10, 100, 1000], 'kernel': ['linear']},
  {'C': [1, 10, 100, 1000], 'gamma': [0.001, 0.0001], 'kernel': ['rbf']},
 ]

You can explore the GridSearchCV documentation for the specific examples. Take a look at the example here (look at 3.2.1)

$\endgroup$
1
  • $\begingroup$ Yes, I just discovered that yesterday, forgot to update my question/answer. Thank you nonetheless for the answer. $\endgroup$ Commented Apr 11, 2017 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.