-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKNN.m
68 lines (32 loc) · 987 Bytes
/
KNN.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
%%%%%%%%%%% KNN Classification %%%%%%%%%%%
clc;
clear all;
close all;
warning off;
training = load('training_examples.txt');
testing = load('testing_examples.txt');
training_features = training(:,1:12);
training_labels = training(:,13);
testing_features = testing(:,1:12);
testing_labels = testing(:,13);
counter =1;
for K=3:2:15
[average_error_testing,average_error_training] = K_Fold_CV(training_features,training_labels,10,K); %%% 10-fold cross validation
error (counter) = average_error_testing;
counter = counter +1;
end
K = 3:2:15
stem(K,error)
%%%%%%%%%%%%%%%%%%%%%%%%% KNN %%%%%%%%%%%%%%%%%%%%%%%
% tic();
% Class = knnclassify(testing_features,training_features,training_labels,7);
% toc();
%
% error = 0;
% for i=1:size(testing_labels)
% if (Class(i) ~= testing_labels(i))
% error = error +1;
% end
% end
%
% accuracy = 1 - error/size(testing_features,1)