x0=zeros(l,1) ;
opts=optimset('MaxIter',10000) ;
ceq=0 ;
X = Train(:,1:20) ;
Y = Train(:,21) ;
l = 48 ;
C = 1 ;
K = X * X' ;
H = diag(Y) * K * diag(Y) ;
A = [] ;
c = [] ;
Aeq = Y' ;
cu = C * ones(l,1) ;
cl = zeros(l,1) ;
f = -ones(l,1) ;
warning off all
answer = quadprog(H,f,A,c,Aeq,ceq,cl,cu,x0,opts);
%----------------------------------------------------
% demostrating margin of error of Training Set
p = answer .* Y ;
total = 0 ;
for i = 1:48
total = p(i) + total
end
total;
% counting up total correctly classified in Training Set
count = 0;
for i = 1:48
if (answer(i) > 0 && answer(i) < C)
count = count + 1;
end
end
count
%-----------------------------------------------------
% calculating b
TestData = 1;
x = Test(TestData,1:20) ;
k = 1;
b1 = Y(k,:);
b2=0;
for i = 1:l
b2 = ((Y(i,:)*answer(i,:)*X(i,:)) .* X(k,:)) +b2;
end
b = b1 - b2;
%Calculate prediction on Test set with kernal
solution = 0;
d = 5;
for i = 1:l
solution = solution + ((answer(i,:)*Y(i,:)) * ((1 + (X(i,:) * x'))).^d) + b;
end
solution