Help on Making an Accurate Confusion Matrix.
Afficher commentaires plus anciens
I am going to submit the code below for a confusion matrix that I have made. (Okay, with some help from another.) When I run the code with my deep learning program, it seems that I get more misses than hits. In other words, I have a lot of entries for "U," which is an unknown variable, a "miss" in other words. I have 154 data files in which the computer is to learn and distinguish between Object A and Object B. What am I doing wrong? I do not think that the data is incorrect or needs to be massaged more. I think the error is in the confusion matrix that I have made. Help! I am confused about the confusion matrix. Can you have a look at the code and possibly help? Here is the code below. Many thanks!
%% Section 12: Create Confusion Matrix Chart
% From the MathWorks Help Center web-site under "confusionchart."
% Description
% confusionchart(trueLabels,predictedLabels) creates a confusion matrix chart from true labels trueLabels and
% predicted labels predictedLabels and returns a ConfusionMatrixChart object.
% The rows of the confusion matrix correspond to the true class and the columns correspond to the predicted class.
% Diagonal and off-diagonal cells correspond to correctly and incorrectly classified observations, respectively.
% Use cm to modify the confusion matrix chart after it is created.
% For a list of properties, see ConfusionMatrixChart Properties.
% Create Confusion Matrix Chart.
% Load a sample of predicted and true labels for a classification problem.
% trueLabels is the true labels for an image classification problem and
% predictedLabels is the predictions of a convolutional neural network.
trueLabels = dsTest.UnderlyingDatastores{1,2}.LabelData(:,2);
newTrueLabels = {};
for idx = 1:numel(trueLabels)
if trueLabels{idx} == 'Van'
newTrueLabels{idx} = 'V';
elseif trueLabels{idx} == 'Man'
newTrueLabels{idx} = 'M';
else
newTrueLabels{idx} = 'U'; % U means 'Unknown'. That is, it is a miss and neither 'Van' nor 'Man'.
end
end
predictedLabels = results.Labels;
newPredictedLabels = {};
for idx = 1:numel(predictedLabels)
if predictedLabels{idx} == 'Van'
newPredictedLabels{idx} = 'V';
elseif predictedLabels{idx} == 'Man'
newPredictedLabels{idx} = 'M';
else
newPredictedLabels{idx} = 'U'; % U means 'Unknown'. That is, it is a miss and neither 'Van' nor 'Man'.
end
end
% Create a confusion matrix chart.
figure(1)
cm = confusionchart(newTrueLabels,newPredictedLabels);
% Modify the appearance and behavior of the confusion matrix chart by changing property values.
% Add column and row summaries and a title.
% A column-normalized column summary displays the number of correctly and incorrectly classified observations
% for each predicted class as percentages of the number of observations of the corresponding predicted class.
% A row-normalized row summary displays the number of correctly and incorrectly classified observations
% for each true class as percentages of the number of observations of the corresponding true class.
cm.ColumnSummary = 'column-normalized';
cm.RowSummary = 'row-normalized';
cm.Title = 'Confusion Matrix for Man and Van Data';
disp("End of Section 12");
disp(" ");
Réponse acceptée
Plus de réponses (2)
Bradley Evans
le 6 Juil 2023
0 votes
Bradley Evans
le 7 Juil 2023
Modifié(e) : Bradley Evans
le 7 Juil 2023
0 votes
Catégories
En savoir plus sur Tuning dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
