How to plot the confusion matrix of more than 2 classes?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
1 Kommentar
Antworten (0)
Siehe auch
Kategorien
Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!