Professional Documents
Culture Documents
clear all;
close all;
filename = 'traindataassignment6 - Copy.csv';
[num,txt,raw] = xlsread(filename);
X = num;
Y = txt;
% rng(10); % For reproducibility
Mdl = fitcknn(X,Y,'NumNeighbors',5,'Standardize',1);
% Examine the resubstitution loss, which, by default,
% is the fraction of misclassifications from the predictions
% of Mdl. (For nondefault cost, weights, or priors, see loss.).
rloss = resubLoss(Mdl)
% The classifier predicts incorrectly for % of the training
% data.
CVMdl = crossval(Mdl);
% Examine the cross-validation loss, which is the average
% loss of each cross-validation model when predicting on data
% that is not used for training.
kloss = kfoldLoss(CVMdl)
predictedY = resubPredict(Mdl);
% Create a confusion matrix chart from the true labels
% Y and the predicted labels predictedY.
% accuracy = accuracy_score(Y(1:999,:),predictedY)
cm = confusionchart(Y(1:999,:),predictedY);
% Modify the appearance and behavior of the confusion
% matrix chart by changing property values. Add a title.