-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathOneNNClassifierZREP.m
More file actions
36 lines (24 loc) · 933 Bytes
/
OneNNClassifierZREP.m
File metadata and controls
36 lines (24 loc) · 933 Bytes
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
function acc = OneNNClassifierZREP(DS,ZRepresentation)
ZRepTrain = ZRepresentation(1:DS.TrainInstancesCount,:);
ZRepTest = ZRepresentation(DS.TrainInstancesCount+1:end,:);
acc = 0;
for id = 1 : DS.TestInstancesCount
%classify_this = DS.Test(id,:);
classify_this = ZRepTest(id,:);
best_so_far = inf;
%best_so_far = 0;
for i = 1 : DS.TrainInstancesCount
%compare_to_this = DS.Train(i,:);
compare_to_this = ZRepTrain(i,:);
distance = ED(compare_to_this, classify_this)^2;
if distance < best_so_far
class = DS.TrainClassLabels(i);
best_so_far = distance;
end
end
if (DS.TestClassLabels(id) == class)
acc = acc + 1;
end
end
acc = acc / DS.TestInstancesCount;
end