Skip to content

Instantly share code, notes, and snippets.

@Salinger
Created January 20, 2013 17:17
Show Gist options
  • Save Salinger/4579980 to your computer and use it in GitHub Desktop.
Save Salinger/4579980 to your computer and use it in GitHub Desktop.
Test code for libsvm-python.
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from svm import *
from svmutil import *
# For learning
t_label = [1,-1,1,-1]
t_data = [
[1.0, 2.0, 3.0],
[3.0, 1.5, 1.0],
[2.0, 3.0, 4.0],
[0.5, 1.0, 1.5]
]
problem = svm_problem(t_label, t_data)
parameter = svm_parameter('-s 0 -t 0')
t = svm_train(problem, parameter)
# For predict
p_label = [1, 1, -1, -1]
p_data = [
[0.3, 0.9, 1.2],
[2.0, 3.0, 4.5],
[3.0, 1.0, 0.3],
[1.0, 0.5, 0.25]
]
result = svm_predict(p_label, p_data , t)
print "[Result]"
for r in result:
print r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment