kernel GridSearchCV parameters

2.4k views Asked by At

can we search for the kernel in Gridserach as below:

and what parameters combinations we should avoid?

parameters = {'C': [0.1, 1, 10, 100, 1000],  
              'gamma': [1, 0.1, 0.01, 0.001, 0.0001,'auto'], 
              'kernel': ['linear', 'poly', 'rbf', 'sigmoid']} 
  Svm = GridSearchCV(Svm, param_grid=parameters, cv=kf,verbose=10)
1

There are 1 answers

0
jhihan On BEST ANSWER

In principle, you can search for the kernel in GridSearch. But you should keep in mind that 'gamma' is only useful for ‘rbf’, ‘poly’ and ‘sigmoid’. That means You will have redundant calculation when 'kernel' is 'linear'. The better way is to use a list of dictionaries rather than a dictionary as an input parameter of param_grid:

svm_linear = {'C': [0.1, 1, 10, 100, 1000], 
              'kernel': ['linear']} 
svm_others = {'C': [0.1, 1, 10, 100, 1000],
              'gamma': [1, 0.1, 0.01, 0.001, 0.0001,'auto'], 
              'kernel': ['poly', 'rbf', 'sigmoid']}
parameters = [svm_linear, svm_others]
Svm = GridSearchCV(Svm, param_grid=parameters, cv=kf,verbose=10)

You could find the similar parameters setting in the scikit-learn document: https://scikit-learn.org/stable/auto_examples/model_selection/plot_grid_search_digits.html

I hop this answer is useful for you. :)