-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathave_error.m
30 lines (21 loc) · 1.17 KB
/
ave_error.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% © Shaghayegh Taheri 2014 All rights reserved. %%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% This function gets four input arguments which are the training set and
%%% testing set and the labels corresponding to each of them.
function error = ave_error(training_set,testing_set,labels_training,labels_testing,K)
% error = 0;
% for i=1:size(testing_set,1)
% label(i,1) = KNN ( training_set , labels_training , testing_set(i,:),K );
%
% error = error + (label(i,1)-labels_testing(i,1))^2; % The error is the number
% end % of differences between the
% labels
Class = knnclassify(testing_set,training_set,labels_training,K);
error = 0;
for i=1:size(testing_set,1)
if (Class(i) ~= labels_testing(i))
error = error + 1; % The error is the number
end
end
error = error/size(testing_set,1);