mtlab 에서 confusion matrix 구현
2 views (last 30 days)
Show older comments
매트랩으로 빌트인 함수인 confusionmat 또는 plotconfusionmat를 사용하지 않고 기본함수로 multi-class confusion matrix를 구현하려면 코드를 어떻게 짜야 할까요? Pred는 [n,1] , groundtruth는 [n,1]배열일 때의 상황입니다.
0 Comments
Answers (1)
Angelo Yeo
on 28 Jan 2024
n = 100;
groundtruth = randi(2 ,n, 1);
pred = randi(2, n, 1);
% Initialize the confusion matrix
numClasses = max(groundtruth);
confusionMatrix = zeros(numClasses);
% Calculate the confusion matrix
for i = 1:length(groundtruth)
trueClass = groundtruth(i);
predictedClass = pred(i);
confusionMatrix(predictedClass, trueClass) = confusionMatrix(predictedClass, trueClass) + 1;
end
actual_1 = confusionMatrix(:,1);
actual_2 = confusionMatrix(:,2);
confusionMatrixTable = table(actual_1, actual_2, 'rownames', ["pred_1", "pred_2"])
0 Comments
See Also
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!