生活随笔
收集整理的這篇文章主要介紹了
matlab的SVM简单的例子
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
SVM簡單的例子,適合初學者代碼學習,含有精確度的表示
編譯環境為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];% (x
,y
)構成的數據點
groups
=[1;1;1;1;-1;-1];%各個數據點的標簽
figure
;
subplot(2,2,1);
Struct1
= svmtrain(data
,groups
,'Kernel_Function','quadratic', 'showplot',true
);%data數據,標簽,核函數,訓練
classes1
=svmclassify(Struct1
,data
,'showplot',true
);%data數據分類,并顯示圖形
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
fprintf('1分類精度為:%f\n' ,CorrectRate1
);
fprintf('2分類精度為:%f\n' ,CorrectRate2
);
fprintf('3分類精度為:%f\n' ,CorrectRate3
);
fprintf('4分類精度為:%f\n' ,CorrectRate4
);
結果為
1分類精度為:0.666667
2分類精度為:1.000000
3分類精度為:0.666667
4分類精度為:0.000000
總結
以上是生活随笔為你收集整理的matlab的SVM简单的例子的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。