采用核函数方法对下列数据进行非线性分类。给出matlab具体代码,及采用训练样本进行测试得到的准确率结果。
x=[0 1 0 1 2 -1];y=[0 0 1 1 2 -1];z=[-1 1 1 -1 1 1];其中,(x,y)代表二维的数据点,z 表示相应点的类型属性。
运行代码:
data=[1,0;0,1;2,2;-1,-1;0,0;1,1];
groups=[1;1;1;1;-1;-1];
figure;
subplot(2,2,1);
Struct1 = svmtrain(data,groups,'Kernel_Function','quadratic', 'showplot',true);
classes1=svmclassify(Struct1,data,'showplot',true);
title('二次核函数');
CorrectRate1=sum(groups==classes1)/6
subplot(2,2,2);
Struct2 = svmtrain(data,groups,'Kernel_Function','rbf', 'RBF_Sigma',0.41,'showplot',true);
classes2=svmclassify(Struct2,data,'showplot',true);
title('高斯径向基核函数(核宽0.41)');
CorrectRate2=sum(groups==classes2)/6
subplot(2,2,3);
Struct3 = svmtrain(data,groups,'Kernel_Function','polynomial', 'showplot',true);
classes3=svmclassify(Struct3,data,'showplot',true);
title('多项式核函数');
CorrectRate3=sum(groups==classes3)/6
subplot(2,2,4);
Struct4 = svmtrain(data,groups,'Kernel_Function','mlp', 'showplot',true);
classes4=svmclassify(Struct4,data,'showplot',true);
title('多层感知机核函数');
CorrectRate4=sum(groups==classes4)/6
运行结果: