Search code examples
pythonmachine-learningscikit-learnsvmhyperparameters

How to perform hyper-paramter tunning for SVC?


I am trying to perform hyper-parameter tuning of my model but this error keeps showing

error :  Invalid parameter svc_c for estimator SVC(). Check the list of available parameters with `estimator.get_params().keys()

I am using the following code :

param_grid = {'svc_c': [5, 10, 100], 
              'svc_gamma': [1,0.1,0.01,0.001],
              'svc_dgree': [1,2,3,4,5,6],
              'svc_kernel': ['rbf']}
grid = GridSearchCV(SVC(),param_grid,refit=True,verbose=3)
grid.fit(x_train_poly,y_train)

Solution

  • you need to use the correct key for the dictionary param_grid. kernel , C , gamma , degree and ... (see doc)

    try this:

    param_grid = {'kernel': ('linear', 'rbf','poly') , 
                  'C':[5, 10, 100],
                  'gamma': [1,0.1,0.01,0.001], 
                  'degree' : [1,2,3,4,5,6]}
    
    grid = GridSearchCV(SVC() , param_grid , refit=True , verbose=3)
    grid.fit(x_train_poly,y_train)