forked from xfsala/DeTraC_COVId19
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfusionMat_MultiClass.m
57 lines (40 loc) · 1.33 KB
/
ConfusionMat_MultiClass.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
function [all_ACC,all_sn, all_sp] = ConfusionMat_MultiClass(cmat,numClasses)
ACC_Class=zeros(1,numClasses); % Accuracy
SN_Class=zeros(1,numClasses); % Sensitivity
SP_Class=zeros(1,numClasses); % Specificity
for C=1:numClasses
TP=0; TN=0; FP=0; FN=0;
%%%%%%%%%%%%%%%%% compute TP
TP =TP +cmat(C,C);
%%%%%%%%%%%%%%%%% compute FN
i=C;
for j=1:numClasses
if j ~= i
FN =FN +cmat(i,j);
end
end
%%%%%%%%%%%%%%%%% compute FP
i=C;
for j=1:numClasses
if j ~= i
FP =FP +cmat(j,i);
end
end
%%%%%%%%%%%%%%%%% compute TN
for i=1:numClasses
if i ~= C
for j=1:numClasses
if j ~= C
TN= TN +cmat(i,j);
end
end
end
end
ACC_Class(1,C)=(TP+TN)/(TP+TN+FP+FN);
SN_Class(1,C) = TP / (TP + FN);
SP_Class(1,C)= TN /(TN + FP);
end
all_ACC= mean(ACC_Class) ;
all_sn= mean(SN_Class) ;
all_sp= mean(SP_Class) ;
end