SVM处理多分类问题

“one-against-one” approach

from sklearn import svm
X = [[0], [1], [2], [3]]
Y = [0, 1, 2, 3]
#“one-against-one” approach
clf = svm.SVC(decision_function_shape='ovo')
clf.fit(X, Y) 

dec = clf.decision_function([[1]])
print dec.shape[1] # 4 classes: 4*3/2 = 6
print clf.predict([[1]])

“one-vs-the-rest” multi-class strategy

from sklearn import svm
# “one-vs-the-rest” multi-class strategy
clf.decision_function_shape = "ovr"
dec = clf.decision_function([[1]])
dec.shape[1] # 4 classes
print dec.shape[1]
print clf.predict([[2.8]])
posted @ 2017-11-24 16:38  james.yj  阅读(1594)  评论(0编辑  收藏  举报