Solution to HW2 #3d,e using ready made SMO2 from Intro to PR book:
http://cgi.di.uoa.gr/~stpatrec/welcome3d.html -pkg download
http://www.elsevierdirect.com/companion.jsp?ISBN=9780123744869 -pkg divided by chapters
Result is the same .5% error rate as Peter's solution, but training seems quite a bit faster and allows better param adjustments.
Questions? email John at jklemail@gmail.com
%read data
[X1400, tokens, Y1400] = readMatrix('data/MATRIX.TRAIN.1400');
X1400 = full(X1400);
[Xtest, tokens, Ytest] = readMatrix('data/MATRIX.TEST');
Xtest = full(Xtest);
%params
C=.1; %.1 gave best result from trying .5, 1
tol=.01;
maxiter=10^6;
eps=10^(-6);
kernel='linear';
method=0;
X=X1400;
Y=Y1400;
N1 = size(X, 1);
N2 = size(Xtest, 1);
Y(Y==0) = -1; %convert 0's to -1's for smo
%train
[a, b, w] = SMO2(X, Y', kernel,0,0,C,tol,maxiter,eps,method);
nSVs = sum(a>0)
marg = 2/sqrt(sum(w.^2))
%test
h = w*Xtest' + b;
h(h>0) = 1;
h(h<0) = 0;
errate = sum(h~=Ytest)/N2
Comments (0)
You don't have permission to comment on this page.