-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKAN_post.m
166 lines (131 loc) · 6.89 KB
/
KAN_post.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
clear
close all
clc
%% Ucitavanje obelezja i KAN pretprocesiranih podataka
close all
data = 4;
if data == 1
positive_all = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Obelezja\positive_norm_all.csv');
negative_all = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Obelezja\negative_norm_all.csv');
X_train = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\norm_X_train.csv');
X_test = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\norm_X_test.csv');
prediction_train = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\norm_prediction_train.csv');
prediction_test = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\norm_prediction_test.csv');
load('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\norm_probs.mat')
ind_ob = [2, 7, 16];
elseif data == 2
positive_all = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Obelezja\positive_PCA.csv');
negative_all = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Obelezja\negative_PCA.csv');
X_train = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\PCA_X_train.csv');
X_test = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\PCA_X_test.csv');
prediction_train = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\PCA_prediction_train.csv');
prediction_test = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\PCA_prediction_test.csv');
load('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\PCA_probs.mat')
ind_ob = [1, 2, 3];
elseif data == 3
positive_all = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Obelezja\positive_LDA.csv');
negative_all = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Obelezja\negative_LDA.csv');
X_train = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\LDA_X_train.csv');
X_test = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\LDA_X_test.csv');
prediction_train = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\LDA_prediction_train.csv');
prediction_test = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\LDA_prediction_test.csv');
load('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\LDA_probs.mat')
ind_ob = [1, 2, 3];
elseif data == 4
positive_all = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Obelezja\positive_norm_all.csv');
negative_all = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Obelezja\negative_norm_all.csv');
X_train = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\norm4_X_train.csv');
X_test = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\norm4_X_test.csv');
prediction_train = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\norm4_prediction_train.csv');
prediction_test = readmatrix('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\norm4_prediction_test.csv');
load('C:\Users\Matija\Desktop\ETF\5. GODINA\3 - MASTER RAD\Data\norm4_probs.mat')
ind_ob = [2, 4, 16];
end
N = length(negative_all);
positive_obelezja = positive_all(ind_ob, :);
negative_obelezja = negative_all(ind_ob, :);
ob1_min = min(min(negative_obelezja(1, :)), min(positive_obelezja(1, :)));
ob2_min = min(min(negative_obelezja(2, :)), min(positive_obelezja(2, :)));
ob3_min = min(min(negative_obelezja(3, :)), min(positive_obelezja(3, :)));
ob1_max = max(max(negative_obelezja(1, :)), max(positive_obelezja(1, :)));
ob2_max = max(max(negative_obelezja(2, :)), max(positive_obelezja(2, :)));
ob3_max = max(max(negative_obelezja(3, :)), max(positive_obelezja(3, :)));
figure
plot3(negative_obelezja(1, :), negative_obelezja(2, :), negative_obelezja(3, :), 'b.', ...
positive_obelezja(1, :), positive_obelezja(2, :), positive_obelezja(3, :), 'r.')
legend('Bez pukotine', 'Sa pukotinom')
xlabel(['Obelezje ', num2str(ind_ob(1))])
ylabel(['Obelezje ', num2str(ind_ob(2))])
zlabel(['Obelezje ', num2str(ind_ob(3))])
title('Prikaz obelezja u prostoru')
axis square
%% Formiranje labela
close all
N_train = round(0.8 * N);
N_test = N - N_train;
Y_train = [zeros(1, N_train), ones(1, N_train)]';
Y_test = [zeros(1, N_test), ones(1, N_test)]';
%% Predikcija klasifikacije na trenirajucem skupu
close all
% Matrica konfuzije
fig = figure;
plotconfusion(Y_train', prediction_train')
fig.Position(3 : 4) = [300, 250];
% title('KAN predikcija na trenirajucem skupu')
title('')
set(gcf, 'Color', 'w')
ylabel('Predikcija')
xlabel('Tacna klasa')
% Iscrtavanje klasifikacione linije na trenirajucem skupu sa greskama
d = 0.15;
[x, y, z] = meshgrid(ob1_min - 0.5 : d : ob1_max + 0.5, ob2_min - 0.5 : d : ob2_max + 0.5, ob3_min - 0.5 : d : ob3_max + 0.5);
t = logical(Y_train);
% Detekcija pogresnih klasifikacija
t_pred = logical(prediction_train);
[idx_greske, ~] = find(t_pred ~= t);
figure
plot3(X_train(t, 1), X_train(t, 2), X_train(t, 3), 'bo');
hold all
plot3(X_train(~t, 1), X_train(~t, 2), X_train(~t, 3), 'rx');
plot3(X_train(idx_greske, 1), X_train(idx_greske, 2), X_train(idx_greske, 3), 'g*');
[faces, verts, ~] = isosurface(x, y, z, f, 0, x);
patch('Vertices', verts, 'Faces', faces, 'FaceColor', 'k', 'edgecolor', ...
'k', 'FaceAlpha', 0.25, 'EdgeAlpha', 0.25);
grid on; box on; axis square
xlabel(['Obelezje ', num2str(ind_ob(1))])
ylabel(['Obelezje ', num2str(ind_ob(2))])
zlabel(['Obelezje ', num2str(ind_ob(3))])
legend('Bez pukotine', 'Sa pukotinom', 'Pogresne klasifikacije', 'Klasifikaciona povrs')
set(gcf, 'Color', 'w')
%% Predikcija klasifikacije na testirajucem skupu
close all
% Matrica konfuzije
fig = figure;
plotconfusion(Y_test', prediction_test')
fig.Position(3 : 4) = [300, 250];
% title('KAN predikcija na testirajucem skupu')
title('')
set(gcf, 'Color', 'w')
ylabel('Predikcija')
xlabel('Tacna klasa')
% Iscrtavanje klasifikacione linije na trenirajucem skupu sa greskama
d = 0.15;
[x, y, z] = meshgrid(ob1_min - 0.5 : d : ob1_max + 0.5, ob2_min - 0.5 : d : ob2_max + 0.5, ob3_min - 0.5 : d : ob3_max + 0.5);
t = logical(Y_test);
% Detekcija pogresnih klasifikacija
t_pred = logical(prediction_test);
[idx_greske, ~] = find(t_pred ~= t);
figure
plot3(X_test(t, 1), X_test(t, 2), X_test(t, 3), 'bo');
hold all
plot3(X_test(~t, 1), X_test(~t, 2), X_test(~t, 3), 'rx');
plot3(X_test(idx_greske, 1), X_test(idx_greske, 2), X_test(idx_greske, 3), 'g*');
[faces, verts, ~] = isosurface(x, y, z, f, 0, x);
patch('Vertices', verts, 'Faces', faces, 'FaceColor', 'k', 'edgecolor', ...
'k', 'FaceAlpha', 0.25, 'EdgeAlpha', 0.25);
grid on; box on; axis square
xlabel(['Obelezje ', num2str(ind_ob(1))])
ylabel(['Obelezje ', num2str(ind_ob(2))])
zlabel(['Obelezje ', num2str(ind_ob(3))])
legend('Bez pukotine', 'Sa pukotinom', 'Pogresne klasifikacije', 'Klasifikaciona povrs')
set(gcf, 'Color', 'w')