-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfmat.m
25 lines (21 loc) · 914 Bytes
/
confmat.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
function [C,err_rate] = confmat(true_lb,est_lb)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ARGUMENTS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% true_lb : vector of n true labels (integers) attached to the data
% est_lb : vector of n estimated labels. The different labels in est_lb
% must be elements of true_lb.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% OUTPUTS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% C : confusion matrix
% err_rate : total error rate
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ind = unique(true_lb);
m = length(ind); % number of classes
C = accumarray([true_lb,est_lb],ones(length(true_lb),1));
% confusion matrixa
C = C(ind,ind);
err_rate = sum(sum(C-diag(diag(C))))/sum(sum(C));
C = diag(1./sum(C,2))*C;
end