-
Notifications
You must be signed in to change notification settings - Fork 6
/
confusion.m
40 lines (29 loc) · 821 Bytes
/
confusion.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
function [oa, aa, ap, K, ua,ub]=confusion(true_label,estim_label)
%
% function confusion(true_label,estim_label)
%
% This function compute the confusion matrix and extract the OA, AA
% and the Kappa coefficient.
%
% INPUT
% easy! just read
l=length(true_label);
nb_c=max(true_label);
confu=zeros(nb_c,nb_c);
for i=1:l
confu(estim_label(i),true_label(i))= confu(estim_label(i),true_label(i))+1;
end
oa=trace(confu)/sum(confu(:)); %overall accuracy
ua=diag(confu)./sum(confu,1)'; %class accuracy
ub = diag(confu)./sum(confu,2); %precison
ua(isnan(ua))=0;
number=size(ua,1);
aa=sum(ua)/number;
ap = sum(ub)/number;
ub(isnan(ub))=0;
% numberb=size(ub,1);
% bb=sum(ub)/numberb;
Po=oa;
Pe=(sum(confu)*sum(confu,2))/(sum(confu(:))^2);
K=(Po-Pe)/(1-Pe);%kappa coefficient
%http://kappa.chez-alice.fr/kappa_intro.htm