where is the error of following code to calculate confusionmat?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Snehal
2025년 4월 22일
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 use ‘confusionmat’ 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!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Support Package for Parrot Drones에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!