Borrar filtros
Borrar filtros

Confusion chart displaying wrong number of class labels

8 visualizaciones (últimos 30 días)
Impala
Impala el 17 de En. de 2023
Comentada: Impala el 25 de Abr. de 2023
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 comentarios
Impala
Impala el 17 de En. de 2023
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 el 17 de En. de 2023
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?

Iniciar sesión para comentar.

Respuesta aceptada

Aman
Aman el 16 de Mzo. de 2023
Editada: Aman el 16 de Mzo. de 2023
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!

Más respuestas (0)

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by