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

2 visualizaciones (últimos 30 días)
Munshida P
Munshida P el 13 de Feb. de 2020
Comentada: Bhaskar R el 13 de Feb. de 2020
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

Respuestas (0)

Categorías

Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by