-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuntitled.m
81 lines (71 loc) · 3.1 KB
/
untitled.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
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
% Provide your own values for the confusion matrix
confusionMatrix = [
50, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
1, 45, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
2, 1, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 50, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 1, 45, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 2, 1, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
50, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
1, 45, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
2, 1, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 50, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 1, 45, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 2, 1, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
50, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
1, 45, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
2, 1, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 50, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 1, 45, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 2, 1, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 2, 1, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
% ... (continue providing values for the remaining rows)
];
% ... (Previous code)
% Create a figure
figure;
% Set axis labels
xlabel('Predicted Classes');
ylabel('True Classes');
% Set axis ticks and labels
xticks(1:19);
yticks(1:19);
% Set title
title('Confusion Matrix Heatmap');
% Display color legend
colorbar('Ticks', [0, 0.33, 0.66, 1], 'TickLabels', {'0%', '33%', '66%', '100%'});
% Initialize the cell colors
cellColors = zeros(size(confusionMatrix, 1), size(confusionMatrix, 2), 3);
% Set colors based on whether the cell is on the diagonal or not
for i = 1:size(confusionMatrix, 1)
for j = 1:size(confusionMatrix, 2)
if i == j
% Diagonal cells
if confusionMatrix(i, j) > 0
% Dark blue for non-zero diagonal cells
cellColors(i, j, :) = [0, 0.2, 0.8];
else
% Light yellow for zero diagonal cells
cellColors(i, j, :) = [1, 1, 0.7];
end
else
% Non-diagonal cells
if confusionMatrix(i, j) > 0
% Light gray for non-zero non-diagonal cells
cellColors(i, j, :) = [0.7, 0.7, 0.7];
else
% White for zero non-diagonal cells
cellColors(i, j, :) = [1, 1, 1];
end
end
end
end
% Display rectangles for each cell with the specified colors
for i = 1:size(confusionMatrix, 1)
for j = 1:size(confusionMatrix, 2)
rectangle('Position', [j-0.5, size(confusionMatrix, 1)-i+0.5, 1, 1], 'FaceColor', cellColors(i, j, :), 'EdgeColor', 'k');
text(j, size(confusionMatrix, 1)-i+1, sprintf('%.2f', confusionMatrix(i, j)), 'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle', 'Color', 'k');
end
end
% Save the figure as a PDF
saveas(gcf, 'confusion_matrix.pdf');