Confusion chart displaying wrong number of class labels

5 ビュー (過去 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!
  1 件のコメント
Impala
Impala 2023 年 4 月 25 日
Thank you! This works very well :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by