我正在使用SVM执行一些机器学习任务。我怀疑数据是非线性的,所以我还包括了RBF内核。我发现带有RBF内核的SVM比线性SVM差很多。我想知道我的分类器参数规范是否做错了什么。
我的代码如下:
from sklearn.svm import LinearSVC
from sklearn.svm import SVC
svm1 = LinearSVC() # performs the best, similar to logistic regression results which is expected
svm2 = LinearSVC(class_weight="auto") # performs somewhat worse than svm1
svm3 = SVC(kernel='rbf', random_state=0, C=1.0, cache_size=4000, class_weight='balanced') # performs way worse than svm1; takes the longest processing time
svm4 = SVC(kernel='rbf', random_state=0, C=1.0, cache_size=4000) # this is the WORST of all, the classifier simply picks the majority class
使用RBF尝试调整您的C
和gamma
参数。Scikit-learn的网格搜索将为您提供帮助。
这是一个入门的示例:
svc = SVC(...)
params = {"C":[0.1, 1, 10], "gamma": [0.1, 0.01, 0.001]}
grid_search = GridSearchCV(svc, params)
grid_search.fit(X,y)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句