How to perform hyper-paramter tunning for SVC?
Question:
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)
Answers:
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)
As the error message states, you are setting invalid parameter names for each hyper-parameter. In this stackoverflow question, a way of showing a list of available hyper-parameters for a given estimator is shown. Then, I’d suggest you to change your code to this:
param_grid = {'C': [5, 10, 100],
'gamma': [1,0.1,0.01,0.001],
'degree': [1,2,3,4,5,6],
'kernel': ['rbf']}
Please, check if those hyper-parameters are actually included in the list that
estimator.get_params().keys()
returns.
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)
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)
As the error message states, you are setting invalid parameter names for each hyper-parameter. In this stackoverflow question, a way of showing a list of available hyper-parameters for a given estimator is shown. Then, I’d suggest you to change your code to this:
param_grid = {'C': [5, 10, 100],
'gamma': [1,0.1,0.01,0.001],
'degree': [1,2,3,4,5,6],
'kernel': ['rbf']}
Please, check if those hyper-parameters are actually included in the list that
estimator.get_params().keys()
returns.