Change class labels of a confusion matrix that has been exported from Classification Learner

18 views (last 30 days)
Hi,
I have exported a confusion matrix from the classification learner app (using the Export plot to figure function), which is where it was generated. How can I change the class labels from numeric to string as the option seems to be greyed out in the figure properties (ClassLabels).
Thank you!

Accepted Answer

Drew
Drew on 12 Apr 2024
In R2023a, one approach is to access the original confusion matrix info, and then create a new confusion chart with different labels. Using the fisheriris dataset, assume we created this confusion matrix in Classification Learner:
Next, export the confusion matrix out of Classification Learner using "Export Plot to Figure", and get access to the ConfusionMatrixChart object and the underlying data. Be sure to run "gca" right after the "Export Plot to Figure" operation, so that the ConfusionMatrixChart is the current figure.
>> ax = gca;
>> ax
ax =
ConfusionMatrixChart (Model 1 (Fine Tree)) with properties:
NormalizedValues: [3×3 double]
ClassLabels: {'setosa' 'versicolor' 'virginica'}
% Normalization is set to "absolute", so the values are the counts
>> ax.NormalizedValues
ans =
50 0 0
0 47 3
0 2 48
% Access the original confusion matrix counts and class labels
>> ConfusionMatrixCounts = ax.NormalizedValues;
>> OriginalClassLabels = ax.ClassLabels;
Define new class labels, and make a new confusionchart with the desired labels.
>> NewClassLabels = {'flower1' 'flower2' 'flower3'};
>> figure(2);
>> confusionchart(ConfusionMatrixCounts,NewClassLabels)

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!