估算器SVR的无效参数丢失 [英] Invalid Parameter loss for estimator SVR
问题描述
这是我的代码
我使用网格搜索cv进行超参数调整.但显示错误.
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()`.
推荐答案
我发现了一些错误:
-
您似乎正在指定仅为
LinearSVR
,而不是SVR
.另一方面,如果您要使用LinearSVR
,则不能指定内核,因为它必须是线性的.
You seem to be specifying a
loss
parameter and possible values, that are only defined for aLinearSVR
, not aSVR
. On another hand, if you do want to use aLinearSVR
, you can't specify a kernel, since it has to be linear.
我还注意到网格定义中的'C':[np.arange(0,20,1)]
会产生错误,因为它会导致嵌套列表.只需使用 np.arange(0,20,1)
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)
假设您有一个 SVR
,以下内容将为您工作:
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)
这篇关于估算器SVR的无效参数丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!