Hossein Hossein - 8 months ago 82
Python Question

An example using python bindings for SVM library, LIBSVM

I am in dire need of a classification task example using LibSVM in python. I don't know how the Input should look like and which function is responsible for training and which one for testing


LIBSVM reads the data from a tuple containing two lists. The first list contains the classes and the second list contains the input data. create simple dataset with two possible classes you also need to specify which kernel you want to use by creating svm_parameter.

>> from libsvm import *
>> prob = svm_problem([1,-1],[[1,0,1],[-1,0,-1]])
>> param = svm_parameter(kernel_type = LINEAR, C = 10)
  ## training  the model
>> m = svm_model(prob, param)
#testing the model
>> m.predict([1, 1, 1])