%%% Classify demo

clc
clear all
close all

NUMBER_OF_FOLDS = 10;

% 10-fold cross-validation on the fisher iris data using the
% Nearest Neighbor classifier and the third and forth column as two 
% features for the classification
load fisheriris;
indices = crossvalind('Kfold',species,NUMBER_OF_FOLDS);
cp = classperf(species); % initializes the CP object
for i = 1:NUMBER_OF_FOLDS
    test = (indices == i); train = ~test;
    class = knnclassify(meas(test,3:4),meas(train,3:4),species(train));
    % updates the CP object with the current classification results
    classperf(cp,class,test);  
end
ConfusionMatrix = cp.CountingMatrix
Accuracy = cp.CorrectRate % queries for the correct classification rate

%% Classperf parameters:
% Indices = crossvalind('Kfold', N, K)
% [Train, Test] = crossvalind('HoldOut', N, P)
% [Train, Test] = crossvalind('LeaveMOut', N, M)
% [Train, Test] = crossvalind('Resubstitution', N, [P,Q])