Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/netlab3.3/confmat.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function [C,rate]=confmat(Y,T) | |
2 %CONFMAT Compute a confusion matrix. | |
3 % | |
4 % Description | |
5 % [C, RATE] = CONFMAT(Y, T) computes the confusion matrix C and | |
6 % classification performance RATE for the predictions mat{y} compared | |
7 % with the targets T. The data is assumed to be in a 1-of-N encoding, | |
8 % unless there is just one column, when it is assumed to be a 2 class | |
9 % problem with a 0-1 encoding. Each row of Y and T corresponds to a | |
10 % single example. | |
11 % | |
12 % In the confusion matrix, the rows represent the true classes and the | |
13 % columns the predicted classes. The vector RATE has two entries: the | |
14 % percentage of correct classifications and the total number of correct | |
15 % classifications. | |
16 % | |
17 % See also | |
18 % CONFFIG, DEMTRAIN | |
19 % | |
20 | |
21 % Copyright (c) Ian T Nabney (1996-2001) | |
22 | |
23 [n c]=size(Y); | |
24 [n2 c2]=size(T); | |
25 | |
26 if n~=n2 | c~=c2 | |
27 error('Outputs and targets are different sizes') | |
28 end | |
29 | |
30 if c > 1 | |
31 % Find the winning class assuming 1-of-N encoding | |
32 [maximum Yclass] = max(Y', [], 1); | |
33 | |
34 TL=[1:c]*T'; | |
35 else | |
36 % Assume two classes with 0-1 encoding | |
37 c = 2; | |
38 class2 = find(T > 0.5); | |
39 TL = ones(n, 1); | |
40 TL(class2) = 2; | |
41 class2 = find(Y > 0.5); | |
42 Yclass = ones(n, 1); | |
43 Yclass(class2) = 2; | |
44 end | |
45 | |
46 % Compute | |
47 correct = (Yclass==TL); | |
48 total=sum(sum(correct)); | |
49 rate=[total*100/n total]; | |
50 | |
51 C=zeros(c,c); | |
52 for i=1:c | |
53 for j=1:c | |
54 C(i,j) = sum((Yclass==j).*(TL==i)); | |
55 end | |
56 end |