function demo_wine_fitting()
load win_train.mat;
win=win_train;
[n,m]=size(win);
X=win(:,2:m);
y=win(:,1);
a=finda(X,y);
load win_test.mat;
win=win_test;
[n,m]=size(win);
X=win(:,2:m);
X=[X ones(n,1)];
y=win(:,1);
y_hat=round(X*a);
plot(1:1:n,y,'r*');hold on;
plot(1:1:n,y_hat,'bo');
error_rate=sum(abs(y-y_hat)>0.5)/n;
fprintf(' Error Rate : %f percent',error_rate*100);
ind=find(abs(y-y_hat)>0.5)
plot(ind,y_hat(ind),'x');
title('Red*:desired target, Blue o:predicted output, x: error prediction')
return

function a=finda(x,y)
n=length(y);
X=[x ones(n,1)];
b=y;
a=inv(X'*X)*X'*b
fprintf(' mean square error: %f\n',mean((X*a-b).^2));
return
