
%
% Small example, visible boundary
%
X = [    0.1071    0.4113    0.2316    0.7638    0.7016    0.2984    0.4182    0.5518    0.5219    0.7753
    0.3962    0.5015    0.7471    0.5453    0.8260    0.1886    0.3757    0.5336    0.1389    0.2500]';
Y = [ 0 0 0 0 0 1 1 1 1 1]';

knn = knnClassify(1,X,Y);
figure; axis([0 1 0 1]); class2DPlot(knn,X,Y); axis square;
print('-dpng','-r72','knnS01.png');
knn=knn.setK(3);
figure; axis([0 1 0 1]); class2DPlot(knn,X,Y); axis square;
print('-dpng','-r72','knnS03.png');
knn=knn.setK(5);
figure; axis([0 1 0 1]); class2DPlot(knn,X,Y); axis square;
print('-dpng','-r72','knnS05.png');


%
% Larger example
%
rand('state',0); randn('state',0);
M0=40; M1=45;
X0 = [.3 ; .6]*ones(1,M0) + [.3 0 ; 0 .3]*randn(2,M0);
X1 = [.7 ; .3]*ones(1,M1) + [.3 0 ; 0 .3]*randn(2,M1);
X=[X0 X1]'; Y=[zeros(1,M0) ones(1,M1)]';
figure; plot(X0(1,:),X0(2,:),'b.',X1(1,:),X1(2,:),'r.'); ax=axis;
knn=knnClassify(1,X,Y);
class2DPlot(knn,X,Y); axis square;
print('-dpng','-r72','knnL01.png');
knn=knn.setK(3);
figure; axis(ax); class2DPlot(knn,X,Y); axis square;
print('-dpng','-r72','knnL03.png');
knn=knn.setK(5);
figure; axis(ax); class2DPlot(knn,X,Y); axis square;
print('-dpng','-r72','knnL05.png');
knn=knn.setK(11);
figure; axis(ax); class2DPlot(knn,X,Y); axis square;
print('-dpng','-r72','knnL11.png');
knn=knn.setK(21);
figure; axis(ax); class2DPlot(knn,X,Y); axis square;
print('-dpng','-r72','knnL21.png');




