Reputation: 33
This is my code
i used grid search cv for hyper parameter tuning. but it shows error.
param_grid = {"kernel" : ['linear', 'poly', 'rbf', 'sigmoid'],
'loss' : ['epsilon_insensitive', 'squared_epsilon_insensitive'],
"max_iter" : [1,10,20],
'C' : [np.arange(0,20,1)]}
model = GridSearchCV(estimator = svr, param_grid = param_grid, cv = 5, verbose = 3, n_jobs = -1)
m1 = model.fit(x_train,y_train)
ValueError: Invalid parameter loss for estimator SVR(C=array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19]),
kernel='linear'). Check the list of available parameters with `estimator.get_params().keys()`.
Upvotes: 0
Views: 573
Reputation: 88295
Some errors that I spotted:
You seem to be specifying a loss
parameter and possible values, that are only defined for a LinearSVR
, not a SVR
. On another hand, if you do want to use a LinearSVR
, you can't specify a kernel, since it has to be linear.
I also noticed that 'C' : [np.arange(0,20,1)]
in the definition of the grid will yield an error, since it results in a nested list. Just use np.arange(0,20,1)
Assuming then you have a SVR
, the following should work for you:
from sklearn.svm import SVR
svr = SVR()
param_grid = {"kernel" : ['linear', 'poly', 'rbf', 'sigmoid'],
"max_iter" : [1,10,20],
'C' : np.arange(0,20,1)}
model = GridSearchCV(estimator = svr, param_grid = param_grid,
cv = 5, verbose = 3, n_jobs = -1)
m1 = model.fit(X_train, y_train)
Upvotes: 1