where is the error of following code to calculate confusionmat?

4 vues (au cours des 30 derniers jours)
Rafid Mustafiz
Rafid Mustafiz le 22 Sep 2018
Réponse apportée : Snehal le 22 Avr 2025
predictedLabels = predict(classifier, testFeatures);
testLabels = testSet.Labels;
confMat = confusionmat(testLabels, predictedLabels);
confMat = bsxfun(@rdivide,confMat,sum(confMat,2))
error is: G and GHAT need to have same number of rows
  1 commentaire
Walter Roberson
Walter Roberson le 22 Sep 2018
What shows up for size(testLabels), size(predictedLabels) ?

Connectez-vous pour commenter.

Réponses (1)

Snehal
Snehal le 22 Avr 2025
I see you are encountering an error while using ‘confusionmat’.  
This issue arises because MATLAB’s ‘confusionmat function requires both input vectors - the true labels and the predicted labels to have the same length and to correspond to the same set of data samples.
Consider checking your input parameters ‘testLabels’ and ‘predictedLabels’ before passing to ‘confusionmat
Below is a sample code on how you can useconfusionmat’ function:
g1 = [3 2 2 3 1 1]'; % Known groups
g2 = [4 2 3 NaN 1 1]'; % Predicted groups
% note that g1 and g2 have same size
C = confusionmat(g1,g2)
You may refer to the following documentation for more information on ‘confusionmat:
Hope this helps!

Catégories

En savoir plus sur MATLAB Support Package for Parrot Drones dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by