【发布时间】:2023-03-12 15:15:02
【问题描述】:
我正在使用 GridSearchCV 进行分类,我的代码是:
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' 时才支持penalty='l1'。,参数:penalty='l1',loss='hinge',dual=False
稍后我将代码更改为:
clf = GridSearchCV(LinearSVC(penalty='l1',dual=False),verbose=2)
我遇到了错误
TypeError: init() 至少需要 3 个参数(给定 3 个)
我也试过了:
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:不支持的参数集:仅当 dual='false' 时才支持penalty='l1'。,参数:penalty='l1',loss='squared_hinge',dual=False
有人知道我应该怎么做吗?
【问题讨论】:
-
只是预感:尝试将固定参数添加到您用于网格搜索的字典中作为单例列表:'penalty': ['l1'], 'dual': [False]。
-
我也试过了,但是它返回错误 ValueError: Unsupported set of arguments: penis='l1' is only supported when dual='false'., 参数:penalty='l1', loss ='squared_hinge', dual=False
标签: python classification svm