使用GridSearchCV时发生值错误 [英] value error happens when using GridSearchCV
问题描述
我正在使用GridSearchCV进行分类,我的代码是:
I am using GridSearchCV to do classification and my codes are:
parameter_grid_SVM = {'dual':[True,False],
'loss':["squared_hinge","hinge"],
'penalty':["l1","l2"]
}
clf = GridSearchCV(LinearSVC(),param_grid=parameter_grid_SVM,verbose=2)
clf.fit(trian_data, labels)
然后,我遇到错误
ValueError:不支持的参数集:仅当dual ='false'时才支持惩罚='l1'。惩罚='l1',损失='铰链',对偶=错误
ValueError: Unsupported set of arguments: penalty='l1' is only supported when dual='false'., Parameters: penalty='l1', loss='hinge', dual=False
后来我将代码更改为:
clf = GridSearchCV(LinearSVC(penalty='l1',dual=False),verbose=2)
我遇到错误
TypeError: init ()至少接受3个参数(
TypeError: init() takes at least 3 arguments (3 given)
我也尝试过:
parameter_grid_SVM = {
'loss':["squared_hinge"]
}
clf = GridSearchCV(LinearSVC(penalty='l1',dual=False),param_grid=parameter_grid_SVM,verbose=2)
clf.fit(trian_data, labels)
但是,我仍然有错误
ValueError:不支持的参数集:只有当double ='false'时才支持惩罚='l1'。,参数:惩罚='l1',loss ='squared_hinge',dual = False
ValueError: Unsupported set of arguments: penalty='l1' is only supported when dual='false'., Parameters: penalty='l1', loss='squared_hinge', dual=False
有人知道我该怎么做吗?
Anyone has idea what I should do to deal with that?
推荐答案
问题,在我的情况下,它写的是十二个 12
,而不是 el two的 l2
。
Had a similar issue and in my case, it was writing twelve 12
instead of 'el two' l2
in some instances.
这篇关于使用GridSearchCV时发生值错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!