function [BESTACC,BESTC,BESTG] = Svmcgforclass (train_label,train,cmin,cmax,gmin,gmax,v,cstep,gstep,accstep)
%SVMCG Cross Validation by Faruto
%%
% by Faruto
%email:[email protected] qq:516667408 Http://blog.sina.com.cn/faruto BNU
%last Modified 2010.01.17
If the percent is reproduced please specify:
% Faruto and Liyang, libsvm-farutoultimateversion
% a toolbox with implements to support vectors 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
Percent of the parameters of svmcg
If Nargin <
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
[x, Y] = Meshgrid (Cmin:cstep:cmax,gmin:gstep:gmax);
[M,n] = size (X);
CG = zeros (m,n);
EPS = 10^ (-4);
Percent record acc with different C & G,and 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 (i,j)), '-G ', Num2str (Basenum^y (I,J))];
CG (I,J) = Svmtrain (Train_label, train, cmd);
if CG (i,j) <=
continue;
End
if CG (i,j) > Bestacc
BESTACC = CG (I,J);
BESTC = basenum^x (i,j);
Bestg = Basenum^y (i,j);
End
If ABS (CG (I,J)-BESTACC) <=eps && bestc > Basenum^x (i,j)
BESTACC = CG (I,J);
BESTC = basenum^x (i,j);
Bestg = Basenum^y (i,j);
End
End
End
Percent to draw the ACC with different C & G
Figure ;
[C,h] = contour (x,y,cg,70:accstep:100);
Clabel (c,h, ' Color ', ' R ');
xlabel (' log2c ', ' FontSize ', ' n ');
ylabel (' log2g ', ' FontSize ', ' n ');
firstline = ' svc parameter selection result graph (contour map) [Gridsearchmethod] ';
secondline = [' Best c= ', Num2str (BESTC), ' g= ', Num2str (BESTG), ...
' cvaccuracy= ', Num2str (BESTACC), '% '];
title ({firstline;secondline}, ' Fontsize ', n);
grid on;
figure;
MESHC (X,Y,CG);
% mesh (X,Y,CG);
% Surf (X,Y,CG);
axis ([cmin,cmax,gmin,gmax,30,100]);
xlabel (' log2c ', ' FontSize ', n);
ylabel (' log2g ', ' FontSize ', n);
zlabel (' accuracy (%) ', ' FontSize ');
firstline = ' svc parameter selection result graph (3D view) [Gridsearchmethod] ';
secondline = [' Best c= ', Num2str (BESTC), ' g= ', Num2str (BESTG), ...
' cvaccuracy= ', Num2str (BESTACC), '% '];
title ({firstline;secondline}, ' Fontsize ', n);
You can download it directly:
LIBSVM-MAT-2.89-3[FARUTOULTIMATE3.0]
Http://www.matlabsky.com/forum-v ...-fromuid-18677.html
To use
For more information on SVM, see:
That dissected thing about SVM [long-term update finishing by Faruto]
Http://www.matlabsky.com/forum-v ...-fromuid-18677.html