How to plot confusion matrix for for multi classes

조회 수: 28(최근 30일)
Hi friends,
I have a confusionmatrix as follows:
X=
[ 6 1 0 0
0 6 0 1
0 0 7 1
1 0 0 5 ]
I want to plot the confusion matrix In a 100 % percentage form such (85.0% ), and lable the classes, but i faced some problems.
i used the following code:
A=[6 1 0 0 ;0 6 0 1; 0 0 7 1;1 0 0 5];
M = confusionchart(A)
M.RowSummary = 'row-normalized';
M.ColumnSummary = 'column-normalized';
h = gca;
h.XTickLabel = {' A',' B',' C','D', ''};
h.YTickLabel = {' A',' B',' C','D',''};
I want to have the same with plot below.
Any help will be highly appreciated

댓글을 달려면 로그인하십시오.

채택된 답변

Srivardhan Gadila 22 Mar 2021
The above confusion matrix chart can only be obtained using the function plotconfusion(targets,outputs) which requires true labels targets and predicted labels outputs, specified as categorical vectors, or in one-of-N (one-hot) form.
Since you have confusion matrix already, you cannot use the above function and can only use confusionchart function.
If you are looking only for the percentages to have in the chart then you can use the Normalization Name-Value Pair argument and set it to 'total-normalized' or 'row-normalized' or 'column-normalized'.
A=[6 1 0 0 ;0 6 0 1; 0 0 7 1;1 0 0 5];
M = confusionchart(A,{' A',' B',' C','D'},'Normalization','total-normalized')
댓글 수: 1표시숨기기 없음
Abdulhakim Alezzi 22 Mar 2021
Thank you very much. It works.

댓글을 달려면 로그인하십시오.

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by