-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.m
52 lines (36 loc) · 1.71 KB
/
Util.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
classdef Util
%UTIL Summary of this class goes here
% Detailed explanation goes here
properties
end
methods
end
methods(Static)
function distance = Euclidean_dist(v1, v2)
v1 = v1(:)';
v2 = v2(:)';
distance = sqrt((v1-v2)*(v1-v2)');
end
function result = statistics(conf_matrix)
sprintf('accuracy = %.4f',sum(diag(conf_matrix)) / sum(sum(conf_matrix)))
if (size(conf_matrix,1) == 2)
sprintf('precision = %.4f', conf_matrix(1,1) / (conf_matrix(1,1) + conf_matrix(2,1)))
sprintf('sensitivity/recall = %.4f', conf_matrix(1,1) / (conf_matrix(1,1) + conf_matrix(1,2)))
sprintf('specificity = %.4f', conf_matrix(2,2) / (conf_matrix(2,2) + conf_matrix(2,1)))
end
conf_matrix
end
function conf_matrix = confusion_matrix(y_pred, y_test, show_out)
conf_matrix = confusionmat(y_test, y_pred);
if(show_out)
sprintf('accuracy = %.4f',sum(diag(conf_matrix)) / sum(sum(conf_matrix)))
if (size(conf_matrix,1) == 2)
sprintf('precision = %.4f', conf_matrix(1,1) / (conf_matrix(1,1) + conf_matrix(2,1)))
sprintf('sensitivity/recall = %.4f', conf_matrix(1,1) / (conf_matrix(1,1) + conf_matrix(1,2)))
sprintf('specificity = %.4f', conf_matrix(2,2) / (conf_matrix(2,2) + conf_matrix(2,1)))
end
conf_matrix
end
end
end
end