資源簡介
用網格法尋找最優解,libsvm網格法查找最優解函數 SVMcgForClass.m(內用libsvmtrain函數來代替svmtrain函數)
代碼片段和文件信息
function?[bestaccbestcbestg]?=?SVMcgForClass(train_labeltraincmincmaxgmingmaxvcstepgstepaccstep)
%SVMcg?cross?validation?by?faruto
%%
%?by?faruto
%Email:patrick.lee@foxmail.com?QQ:516667408?http://blog.sina.com.cn/faruto?BNU
%last?modified?2010.01.17
%%?若轉載請注明:
%?faruto?and?liyang??LIBSVM-farutoUltimateVersion?
%?a?toolbox?with?implements?for?support?vector?machines?based?on?libsvm?2009.?
%?
%?Chih-Chung?Chang?and?Chih-Jen?Lin?LIBSVM?:?a?library?for
%?support?vector?machines?2001.?Software?available?at
%?http://www.csie.ntu.edu.tw/~cjlin/libsvm
%%?about?the?parameters?of?SVMcg?
if?nargin?10
????accstep?=?4.5;
end
if?nargin?8
????cstep?=?0.8;
????gstep?=?0.8;
end
if?nargin?7
????v?=?5;
end
if?nargin?5
????gmax?=?8;
????gmin?=?-8;
end
if?nargin?3
????cmax?=?8;
????cmin?=?-8;
end
%%?X:c?Y:g?cg:CVaccuracy
[XY]?=?meshgrid(cmin:cstep:cmaxgmin:gstep:gmax);
[mn]?=?size(X);
cg?=?zeros(mn);
eps?=?10^(-4);
%%?record?acc?with?different?c?&?gand?find?the?bestacc?with?the?smallest?c
bestc?=?1;
bestg?=?0.1;
bestacc?=?0;
basenum?=?2;
for?i?=?1:m
????for?j?=?1:n
????????cmd?=?[‘-v?‘num2str(v)‘?-c?‘num2str(?basenum^X(ij)?)‘?-g?‘num2str(?basenum^Y(ij)?)];
????????cg(ij)?=?libsvmtrain(train_labe
評論
共有 條評論