how do i display zeros in confusion chart?
조회 수: 13 (최근 30일)
이전 댓글 표시
In confusion chart the cells correspond to zero values are getting blank which is normal for matlab...but i need to show these zero values...is there any way?

댓글 수: 0
답변 (1개)
Udit06
2024년 11월 29일
Hi Arnab,
To display zeros instead of blank spaces, you can create a confusion matrix and display it using a heatmap while ensuring that all values, including zeros, are visible. You can find the code for the same below:
numSamples = 100;
numClasses = 5;
% Generate random true labels and predicted labels
trueLabels = randi([1, numClasses], numSamples, 1);
predictedLabels = trueLabels; % assigning predictLabels as trueLabels so that the confusion matrix contain some zeros
% Compute the confusion matrix
confMat = confusionmat(trueLabels, predictedLabels);
% Create a heatmap for the confusion matrix
h = heatmap(confMat, 'ColorbarVisible', 'off');
h.Colormap = [1 1 1]; % White
h.CellLabelColor = 'black'; % Ensure labels are visible
h.CellLabelFormat = '%d'; % Display as integers
% Add titles and labels for clarity
h.Title = 'Confusion Matrix';
h.XLabel = 'Predicted Class';
h.YLabel = 'True Class';
h.XDisplayLabels = string(1:numClasses);
h.YDisplayLabels = string(1:numClasses);
You can refer to the following MathWorks documentation to understand more about the heatmap function:
I hope this helps.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!