バージョン2.X のころと書き方変わっているのでメモ

libsvm 2.X 時代の書き方
( 集合知プログラミングのサンプル )

from svm import *
prob = svm_problem([1,-1],[[1,0,1],[-1,0,-1]])

param = svm_parameter(kernel_type = LINEAR, C = 1) <- 3.12 だとここでエラーになる
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'kernel_type' 

m = svm_model(prob, param)
m.predict([1, 1, 1])


livsbm-3.12 での書き方

Python 2.7.3 (default, Oct 23 2012, 16:35:33)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from svmutil import *
>>> prob = svm_problem([1,-1],[[1,0,1],[-1,0,-1]])
>>> m = svm_train(prob, '-t 0 -c 1')
*
optimization finished, #iter = 1
nu = 0.250000
obj = -0.250000, rho = 0.000000
nSV = 2, nBSV = 0
Total nSV = 2
>>> print svm_predict([1],[[1,1,1]],m)[0][0]
Accuracy = 100% (1/1) (classification)
1.0
>>>