% Nearest neighbor classification.
N = 100;

% Generate 100 points for each of three classes: means (0,0), (0,1), (1,1), and
% covariances [2 1; 1 4], [2 0 ; 0 2] and [2 0 ; 0 2].
D = gendatgauss([N N N], [0 0; 0 1; 1 1]* 3, cat(3, [2 1; 1 4], eye(2), eye(2)));

% Randomly split the data into training and testing, using 1/2 the data from each class.
[ Train, Test ] = gendat(D, [ N/2 N/2 N/2 ])

% Create quadratic discriminant, run and report error on test set.
C = knnc(Train, 1);
C2 = knnc(Train, 9);

Classification = Test*C;
disp('   Classification error for 1-NN classifier:')
testc(Classification)
Class2 = Test * C2;
disp('  Classification error for 9-NN classifier:')
testc( Classification )

% Display the data and the decision boundary.
figure;
scatterd(Train);
hold on;
plotc(C);
plotc(C2,'r');
