-
Notifications
You must be signed in to change notification settings - Fork 39
/
OneNNClassifierMinkowski.m
60 lines (49 loc) · 2.13 KB
/
OneNNClassifierMinkowski.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
function acc = OneNNClassifierMinkowski(DS,param1, NormalizationIndex)
acc = 0;
for id = 1 : DS.TestInstancesCount
disp(id);
classify_this = DS.Test(id,:);
if NormalizationIndex==2
classify_this = MinMaxNorm(classify_this,0.001,1);
elseif NormalizationIndex==3
classify_this = UnitLengthNorm(classify_this);
elseif NormalizationIndex==4
classify_this = MeanNorm(classify_this);
elseif NormalizationIndex==5
classify_this = MedianNorm(classify_this);
elseif NormalizationIndex==6
elseif NormalizationIndex==7
classify_this = SigmoidNorm(classify_this);
elseif NormalizationIndex==8
classify_this = TanhNorm(classify_this);
end
best_so_far = inf;
for i = 1 : DS.TrainInstancesCount
compare_to_this = DS.Train(i,:);
if NormalizationIndex==2
compare_to_this = MinMaxNorm(compare_to_this,0.001,1);
elseif NormalizationIndex==3
compare_to_this = UnitLengthNorm(compare_to_this);
elseif NormalizationIndex==4
compare_to_this = MeanNorm(compare_to_this);
elseif NormalizationIndex==5
compare_to_this = MedianNorm(compare_to_this);
elseif NormalizationIndex==6
[classify_this,compare_to_this] = AdaptiveScaling(classify_this,compare_to_this);
elseif NormalizationIndex==7
compare_to_this = SigmoidNorm(compare_to_this);
elseif NormalizationIndex==8
compare_to_this = TanhNorm(compare_to_this);
end
distance = minkowski(compare_to_this,classify_this, param1);
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