wine_data;
for ccol=2:size(wine_ins,2),
   minV=min(wine_ins(:,ccol));
   maxV=max(wine_ins(:,ccol));
   varCol=var(wine_ins(:,ccol));
   wine_ins(:,ccol) = (wine_ins(:,ccol)-minV)/sqrt(varCol);
end

fprintf(1,'Now classifying the Wine dataset with %d instances using leave-one-out.\n', size(wine_ins,1));
total_ins = 0;
total_correct = 0;
total_wrong = 0;
for ind=1:size(wine_ins,1),
   wine_ins_rest=wine_ins([1:(ind-1) (ind+1):size(wine_ins,1)],:);
   c1_ind=find(wine_ins_rest(:,1)==1);
   wine_ins_rest_c1=wine_ins_rest(c1_ind,2:end);
   c2_ind=find(wine_ins_rest(:,1)==2);
   wine_ins_rest_c2=wine_ins_rest(c2_ind,2:end);
   c3_ind=find(wine_ins_rest(:,1)==3);
   wine_ins_rest_c3=wine_ins_rest(c3_ind,2:end);
   c1_mean = mean(wine_ins_rest_c1);
   c2_mean = mean(wine_ins_rest_c2);
   c3_mean = mean(wine_ins_rest_c3);
   x=wine_ins(ind,2:end);
   d1 = sum((x-c1_mean).^2);
   d2 = sum((x-c2_mean).^2);
   d3 = sum((x-c3_mean).^2);
   fprintf(1,'For instance %d (from class %d), the distance to class means are %8.6f %8.6f %8.6f.\n',...
      ind, wine_ins(ind,1), d1,d2,d3);
   dists=[d1 d2 d3];
   [dummy classified_ind]=min(dists);
   fprintf(1,'   using minimum distance classifier, it is classified as class %d, which is ',classified_ind);
   if classified_ind==wine_ins(ind,1),
      fprintf(1,'correct.\n');
      total_correct = total_correct + 1;
   else
      fprintf(1,'wrong.\n');
      total_wrong = total_wrong + 1;
   end
   total_ins = total_ins + 1;
   %pause;
end
fprintf(1,'Using leave-one-out classification, there are %d correct out of %d, which is %8.6f %%.\n',...
   total_correct, total_ins, (100.0*total_correct/total_ins));

