How to plot the confusion matrix of more than 2 classes?

조회 수: 2 (최근 30일)
Munshida P
Munshida P 2020년 2월 13일
댓글: Bhaskar R 2020년 2월 13일
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
kk=1;
for person=1:40
for j = 1:test(person).Count
queryImage = read(test(person),j);
queryFeatures = extractHOGFeatures(queryImage);
actualLabel = predict(faceClassifier,queryFeatures);
actualLabel=char(actualLabel);
predictedLabel=test(person).Description;
al(kk)=str2num(actualLabel(2:length(actualLabel)))
pl(kk)=str2num(predictedLabel(2:length(predictedLabel)))
kk=kk+1;
% Map back to training set to find identity
%booleanIndex = strcmp(actualLabel, personIndex);
%integerIndex = find(booleanIndex);
end
end
if isempty(al)==0
accuracy=length(find(pl==al))/size(test,1)
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by