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]])


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM