How to calculate the accuracy of the classifier ? and show the confusion matrix.

조회 수: 4 (최근 30일)
Munshida P
Munshida P 2020년 1월 28일
답변: Hitham 2020년 9월 25일
I had implemented a simple face recognition code. how to calculate its accuracy? and how to plot the confusion matrix .
clc
clear
% Load Image dataset
faceDatabase = imageSet('facedatabaseatt','recursive');
%splitting into training and testing sets
[training,test] = partition(faceDatabase,[0.8 0.2]);
% Extract HOG Features for training set
featureCount = 1;
for i=1:size(training,2)
for j = 1:training(i).Count
trainingFeatures(featureCount,:) = extractHOGFeatures(read(training(i),j));
% imshow(read(training(i),j));
%pause(0.0011);
trainingLabel{featureCount} = training(i).Description;
featureCount = featureCount + 1;
end
personIndex{i} = training(i).Description;
end
% Create 40 class classifier
faceClassifier = fitcknn(trainingFeatures,trainingLabel);
%testing
for person=1:40
for j = 1:test(person).Count
queryImage = read(test(person),j);
queryFeatures = extractHOGFeatures(queryImage);
actualLabel = predict(faceClassifier,queryFeatures) %actuallabel
C=test(person).Description; % predictedlabel
predictedLabel= cellstr(C) %converting into cell array
end
end

답변 (1개)

Hitham
Hitham 2020년 9월 25일
confusionmat computes the Confusion matrix as.
[cm,order] = confusionmat(actualLabel,predictedLabel);
Or, you can use my function.
function [c_matrix]=confusionmat1(actual,predict)
% It computes confusion matrix
classList=unique(actual);
N=length(classList);
cm = zeros(N,N);
for j=1:length(actual)
posClassGT = strmatch(actual{j}, classList, 'exact');
posClass = strmatch(predict{j}, classList, 'exact');
cm(posClassGT,posClass) = cm(posClassGT,posClass) + 1;
end
end

카테고리

Help CenterFile Exchange에서 Pattern Recognition and Classification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by