-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathErrorAnalyze.m
More file actions
82 lines (72 loc) · 2.03 KB
/
ErrorAnalyze.m
File metadata and controls
82 lines (72 loc) · 2.03 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
%%
%
%
function ErrorAnalyze(realy,predy)
errtypes = analyze(realy,predy);
accurate = accurancy(errtypes,realy);
confuseM = confuseMatrix(realy,predy);
fprintf('total accurancy: %d',accurate);
ploterr(errtypes);
end
function [confuseM] = confuseMatrix(realy, predicty)
types = union(realy,realy);
confuseM = zeros(length(types),length(types));
for i = 1 : length(types)
rtype = types(i);
rI = find(realy == rtype);
pred = predicty(rI);
tnum = length(rI);
for j = 1 : length(types)
ptype = types(j);
pI = find(pred == ptype);
pnum = length(pI);
confuseM(i,j) = pnum / tnum;
end
end
end
function [errtypes] = analyze(realy,predicty)
if size(predicty,2) ~= 1 || size(realy,2) ~= 1 || size(realy,1) ~= size(predicty,1)
return;
end
types = union(realy,realy);
errtypes = cell( size(types,1),1);
for i=1:length(predicty)
if predicty(i) ~= realy(i)
errtypes{realy(i)}(end+1,:) = predicty(i);
end
end
end
function [accurancies] = accurancy(errtypes,realy)
totalerr = 0;
for i =1:length(errtypes)
totalerr = totalerr + length(errtypes{i});
end
accurancies = 1- totalerr / length(realy) ;
end
function ploterr(errtypes)
overall = zeros(length(errtypes),1);
for i = 1:length(errtypes)
overall(i) = size(errtypes{i},1);
end
x = 1:20;
plot(x,overall,'r-+');
xlabel('type');
ylabel('errnum');
title('prediction err num');
set(gca,'XTick',1:length(errtypes));
for i = 1:length(errtypes)
figure(1+i);
data = errtypes{i};
y = [];
for j = 1:length(errtypes)
y(j) = length(find(data == j));
end
subplot(2,1,1);
bar(x,y);
title(sprintf('%dth err analysis',i));
set(gca,'XTick',1:length(errtypes));
subplot(2,1,2);
plot(data);
set(gca,'YTick',1:length(errtypes));
end
end