淘先锋技术网

首页 1 2 3 4 5 6 7

6.1

6.2

from libsvm.svm import *
from libsvm.svmutil import *
y = [1,1,1,1,1,1,-1,-1,-1,-1,-1,-1]
x = [{1:0.774,2:0.376},{1:0.634,2:0.264},{1:0.608,2:0.318},{1:0.556,2:0.215},{1:0.403,2:0.237},
     {1:0.481,2:0.149},{1:0.666,2:0.091},{1:0.243,2:0.267},{1:0.245,2:0.057},{1:0.343,2:0.099},
     {1:0.639,2:0.161},{1:0.657,2:0.198}]
yt = [1,1,-1,-1,-1]
xt = [{1:0.697,2:0.46},{1:0.437,2:0.211},{1:0.719,2:0.103},{1:0.593,2:0.042},{1:0.36,2:0.37}]
#y、x是训练集,yt、xt是测试集
prob = svm_problem(y, x)
param = svm_parameter('-t 2 -c 35')  #t = 2是高斯核,t = 0是线性核
model = svm_train(prob, param)
p_label, p_acc, p_val = svm_predict(yt, xt, model)
p_label

高斯核和线性核训练出来没有区别,支持向量一致

6.3

转载于:https://www.cnblogs.com/zwtgyh/p/11433902.html