Confusion chart displaying wrong number of class labels

조회 수: 6 (최근 30일)
Impala
Impala 2023년 1월 17일
댓글: Impala 2023년 4월 25일
Hi,
I'm classifying accelerometer position data into 2 classes: movement or stable using a binary decision tree model. I've applied the model to my test data and I'm trying to plot the confusion chart. However, the confusion chart appears to have 4 class labels (1, 2, movement, stable) when the data only has two classes (movement or stable). I'm not sure why this is happening.
I have attached my data (actTest (known classes) and TestPredModel (predicted classes)), as well as an image of the confusion matrix I get when I run the following code:
confusionchart(actTest,TestPredModel,'Normalization','row-normalized')
Any help will be much appreciated!
Thanks!
  댓글 수: 2
Impala
Impala 2023년 1월 17일
It appears that if I accidentally type something into one of the cells of my categorical variables (actTest, TestPredModel), which is not one of my classes and then correct it later, whatever I typed appears on the confusion chart.
e.g. if I type 'A' in actTest(1,1) and then correct it back to its original values ('Stable') and run the confusionchart funtion above, A appears as a class even though I corrected the value. Please see attached image.
Is this a bug?
Impala
Impala 2023년 1월 17일
Sorry, another quick update - when I change the data type to cell arrays, the confusion chart displays the correct number of classes (see attached). I have used the following syntax:
actTest2 = cellstr(actTest);
TestPredModel2 = cellstr(TestPredModel)
confusionchart(actTest2,TestPredModel2,'Normalization','row-normalized')
Why doesn't the confusion chart work well with categorical arrays?

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

채택된 답변

Aman
Aman 2023년 3월 16일
편집: Aman 2023년 3월 16일
Hi,
I understand that you have made model for classification and to evaluate the model performance you are using confusion matrix, but there are incorrect number of classes in the confusion chart.
When change the categorical array via cell update or manual update through code, a new category is created. If you later modify the same cell, the categorical array will be updated but the newly created category will still be there with zero instances. You can use the “removecats” method to remove the unused categories before plotting the confusion chart. Please refer the below code for your reference.
summary(actTest);
actTest = removecats(actTest);
summary(actTest);
confusionchart(actTest,TestPredModel,'Normalization','row-normalized');
Hope it helps!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by