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

18 ビュー (過去 30 日間)
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!

採用された回答

Drew
Drew 2024 年 4 月 12 日
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)

その他の回答 (0 件)

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by