필터 지우기
필터 지우기

Plot Confusion Matrix for a Trained Classifier

조회 수: 4 (최근 30일)
Alessandro Fascetti
Alessandro Fascetti 2018년 10월 5일
댓글: Towfeeq Fairooz 2021년 12월 19일
I trained a classifier for 7500 instances and 3 classes. Since the confusion matrix tab inside the Classifier App will not let me change font size and title (the most absurd thing ever...) I had to export the classifier as a function and do it manually. So I calculate the validationPredictions as suggested in the generated .m file
partitionedModel = crossval(trainedClassifier.ClassificationSVM, 'KFold', 5);
% Compute validation accuracy
validationAccuracy = 1 - kfoldLoss(partitionedModel, 'LossFun', 'ClassifError');
% Compute validation predictions and scores
[validationPredictions, validationScores] = kfoldPredict(partitionedModel);
This should be trivial at this point, but apparently it is not. When using:
C = confusionmat(response, validationPredictions);
the output C matrix is a 3-by-3 containing the real vs predicted classes. Then running:
plotconfusion(response,validationPredictions)
hangs Matlab and nothing shows up (this should take a split second). What is the issue?

답변 (2개)

James Herman
James Herman 2019년 7월 11일
Alessandro - I figured out why this isn't working for me, the data type of the arguments passed to the function (plotconfusion) needs to be "categorical". Even if you're passing a list of integers you need to convert it using the "categorical" function.
  댓글 수: 1
Towfeeq Fairooz
Towfeeq Fairooz 2021년 12월 19일
It has been a long time but I thought this might help someone. So.
You are correct; I experienced the same problem and was only able to resolve it by adding categorical to the arguments of classifier app's (export function)
However, I did not clip any sections of the trainedClassier code it remains well within the code.
inputData =[X,y]; % X = data features, y = target
[myClassifier, myValidationAccuracy] = trainClassifier(inputData);
y_predicted = myClassifier.predictFcn(X_inputData);
plotconfusion(categorical(y_inputData),categorical(y predicted));

댓글을 달려면 로그인하십시오.


Ali Moshrefzadeh
Ali Moshrefzadeh 2019년 5월 26일
The form of the input matrixes for
plotconfusion(targets,outputs)
is different form the output of
C = confusionmat
You should either use confusionchart(C) to plot the output of confusionmat as a confusion matrix or prepare the proper matrixes for plotconfusion.
  댓글 수: 1
James Herman
James Herman 2019년 7월 10일
You're incorrect. Alessandro Fascetti has used the function precisedly as it is intended. I have the same issue - the function "plotconfusion" doesn't return an error, it simply hangs up during execution.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Classification Learner App에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by