Z=csvread('glass_data_HW6.csv');
[rows,cols]=size(Z);
disp([rows,cols])
V=ones(rows,10);
for k=1:9
    V(:,k+1)=Z(:,k);
end
y=Z(:,10);
A=V'*V;
b=V'*y;
w=A\b;
fit=V*w;
r=fit-y;
sse=r'*r;
ybar=sum(y)/rows;
var=y-ybar;
sst=var'*var;
rsq=(sst-sse)/sst;
disp(rsq)
cmat=zeros(3,3);
for i=1:rows
    class=y(i);
    bin=2;
    if(fit(i)<1.5)bin=1;end;
    if(fit(i)>4)bin=6;end;
    if(bin==1&&class==1)cmat(1,1)=cmat(1,1)+1;end
    if(bin==2&&class==1)cmat(2,1)=cmat(2,1)+1;end
    if(bin==6&&class==1)cmat(3,1)=cmat(3,1)+1;end
    if(bin==1&&class==2)cmat(1,2)=cmat(1,2)+1;end
    if(bin==2&&class==2)cmat(2,2)=cmat(2,2)+1;end
    if(bin==6&&class==2)cmat(3,2)=cmat(3,2)+1;end
    if(bin==1&&class==6)cmat(1,3)=cmat(1,3)+1;end
    if(bin==2&&class==6)cmat(2,3)=cmat(2,3)+1;end
    if(bin==6&&class==6)cmat(3,3)=cmat(3,3)+1;end
end
disp(cmat)
tot1s=cmat(1,1)+cmat(2,1)+cmat(3,1);
tot2s=cmat(1,2)+cmat(2,2)+cmat(3,2);
tot6s=cmat(1,3)+cmat(2,3)+cmat(3,3);
totall=tot1s+tot2s+tot6s;
disp([tot1s,tot2s,tot6s,totall])
accur1s=cmat(1,1)/tot1s;
accur2s=cmat(2,2)/tot2s;
accur6s=cmat(3,3)/tot6s;
accurall=(cmat(1,1)+cmat(2,2)+cmat(3,3))/totall;
disp([accur1s,accur2s,accur6s,accurall])