西瓜书课后习题——第六章

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

posted @ 2019-08-30 11:10  zwtzz  阅读(1295)  评论(0编辑  收藏  举报