how do i display zeros in confusion chart?

6 visualizaciones (últimos 30 días)
Arnab Mondal
Arnab Mondal el 9 de Mzo. de 2022
Respondida: Udit06 el 29 de Nov. de 2024
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?

Respuestas (1)

Udit06
Udit06 el 29 de Nov. de 2024
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.

Categorías

Más información sobre Red en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by