Error using confusionchart (line 68) Order must be an exact permutation of the class labels.

5 visualizaciones (últimos 30 días)
Please help with this error - what could be the cause?
Error using confusionchart (line 68)
Order must be an exact permutation of the class labels.
  2 comentarios
Abdulqader faris
Abdulqader faris el 2 de Jul. de 2024
can u help me my error in the code is :
Error using confusionchart (line 68)
Vectors of true and predicted labels must have the same number of observations.
Error in untitled5 (line 88)
confusionchart(TTest,YTest);

Iniciar sesión para comentar.

Respuesta aceptada

Shivani
Shivani el 18 de Jun. de 2024
The error you're encountering with confusionchart in MATLAB indicates that the order of the classes specified in the confusion matrix does not match the order of the class labels provided. To resolve this error, you need to ensure that the order of the classes in the confusion matrix matches the order of the class labels.
While it is difficult to determine the exact reason for this error without the data and code, some of the reasons this can happen include mismatch in class labels, duplicates or missing labels, incorrect data type, and unrecognized labels.
The following workarounds may help resolve the error you are encountering:
  • Check the class labels in your dataset and ensure that the sorting array is an exact permutation of these labels. No label should be missing, and there should be no additional labels that are not present in your data. You can use the unique function to find all unique labels in your true labels and predicted labels arrays. You can use the following link for implementation details on using the unique function: https://www.mathworks.com/help/matlab/ref/double.unique.html
  • Ensure there are no typos in your class labels
  • Make sure the sorting array and the class labels in your dataset are of the same data type
  • The sorting array should include each class label from your dataset exactly once, in the order you wish to have them displayed in the confusion matrix.
Since I don't have access to the dataset you're using, I'll include a simple example with some sample data to illustrate how this issue can be resolved:
trueLabels = [1; 2; 3; 1; 2; 3; 1; 2; 3];
predictedLabels = [1; 2; 3; 2; 1; 3; 3; 1; 2];
%additional class label '4' will cause an error since it is not present in trueLabels or predictedLabels
%classLabels = [1; 2; 3; 4]; %uncommenting this line will replicate the error
% Define the class labels
classLabels = [1; 2; 3];
% Create the confusion matrix and the chart
confusionMat = confusionmat(trueLabels, predictedLabels);
confusionchart(confusionMat, classLabels);
Additionally, you can refer to the following MATLAB documentation link for more details on implementation: https://www.mathworks.com/help/stats/confusionchart.html

Más respuestas (0)

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by