-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyConfusionPlot.m
More file actions
49 lines (37 loc) · 1.29 KB
/
myConfusionPlot.m
File metadata and controls
49 lines (37 loc) · 1.29 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
function [ ] = myConfusionPlot( predicttest,op,k,s )
% Calculates & Plots Confusion Matrix
%% Calculate Confusion Matrix
conf=sum(predicttest==op)/length(predicttest);
disp(['Accuracy of system from Confusion Matrix is : ',num2str(conf*100),' %'])
yu=unique(predicttest);
confMat=zeros(length(yu));
for i=1:length(yu)
for j=1:length(yu)
confMat(i,j)=sum(predicttest==yu(i) & op==yu(j));
end
end
disp(['Confusion :'])
disp(confMat)
%% Plots Confusion Matrix
figure;
% Convert this data to a [numClasses x length(op)] matrix
targets = zeros(3,length(op));
outputs = zeros(3,length(op));
targetsIdx = sub2ind(size(targets), op, 1:length(op));
outputsIdx = sub2ind(size(outputs), predicttest, 1:length(op));
targets(targetsIdx) = 1;
outputs(outputsIdx) = 1;
% Plot the confusion matrix for a 3-class problem
plotconfusion(targets,outputs)
h = gca;
h.XTickLabel = {'Class ai','Class bA','Class lA',''};
h.YTickLabel = {'Class ai','Class bA','Class lA',''};
h.FontSize = 12;
h.FontWeight = 'bold';
h.YTickLabelRotation = 90;
title(['Confusion with acc. = ',num2str(conf*100),'% & K = ',num2str(k),' & S = ',num2str(s),],'FontSize',12,'FontWeight','bold')
set(gca,'FontSize',14,'FontWeight','bold')
print('-djpeg', ['Confusion_Matrix_K_',num2str(k),'_S_',num2str(s),'.jpg'], '-r300');
close all;
%
end