Contents

clc; close all; clear all;

load citiesBig1

[n,d] = size(X);
[t,d] = size(Xtest);

%{
for k=[1 3 10]
    model = cnn(X,y,k);
    yhat1 = model.predict(model,X);
    errTraining = sum(yhat1 ~= y)/n;

    yhat2 = model.predict(model,Xtest);
    errTest = sum(yhat2 ~= ytest)/t;
end
%}

K Nearest Neighbour

model = knn(X,y,3);
yhat1 = model.predict(model,X);
errTraining = sum(yhat1 ~= y)/n
yhat2 = model.predict(model,Xtest);
errTest = sum(yhat2 ~= ytest)/t
size(model.X)
classifier2Dplot1(X,y,Xtest,ytest,model);
errTraining =

   0.003868340685443


errTest =

   0.012147947064812


ans =

       14735           2

Condensed Nearest Neighbour

model = cnn(X,y,3);
yhat1 = model.predict(model,X);
errTraining = sum(yhat1 ~= y)/n
yhat2 = model.predict(model,Xtest);
errTest = sum(yhat2 ~= ytest)/t
size(model.X)
classifier2Dplot1(X,y,Xtest,ytest,model);

%{
testValue=[11 13 15 19 1 6 2];
y=[1; 0; 1; 1; 0; 0; 1];
k=3;
[g n]=size(testValue);

[currentKMin indices]=sort(testValue(1:k));
for i=k+1:n
    if currentKMin(end)>testValue(i);
        currentKMin(end)=testValue(i);
        indices(end)=i;
        [currentKMin subIndex]=sort(currentKMin);
        % sort the index array depending on the sorting of the element
        indices=indices(subIndex);
    end
end

yhat(1,1)=mode(y(indices))

%}
errTraining =

   0.007533084492704


errTest =

   0.017577197149644


ans =

   457     2