本文介绍了将Python绑定用于SVM库LIBSVM的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我非常需要在python中使用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 testingThanks
推荐答案
LIBSVM从包含两个列表的元组中读取数据.第一个列表包含类,第二个列表包含输入数据.用两个可能的类创建简单的数据集您还需要通过创建svm_parameter来指定要使用的内核.
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 classesyou 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])
这篇关于将Python绑定用于SVM库LIBSVM的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!