How to use fitcknn for multiple classes?

I am working on facial expression recognition. i made a dataset contain features & classes of 213 images.
  • Step1: Each row of my dataset represents the features of 1 image. so for 213 images 213 rows
  • Step2: the last column represents classes like; 1,2,3,4,5,6,7 i used fitcsvm it gives great results but now i want to use knn.
QUESTIONS
  1. How to use fitcknn or any knn classifier to classify
  2. along with cross-validation
  3. and find accuracy precision and recall
  4. help me with this code
clc;
close all;
data = load(fullfile('.', 'Features', 'jaffe_features.txt'));
% features_train = data(1:128,:);
% features_test = data(128:end,:);
nRows = size(data,1);
randRows = randperm(nRows); % generate random ordering of row indices
features = data(randRows(1:end),:);
labels1 = data(:,end);
[labels] = labels1;
Mdl = fitcknn(features,labels,'NumNeighbors',5,...
'ClassNames',{'1','2','3','4','5','6','7'},'Distance','euclidean', 'Standardize',1);
loss = resubLoss(Mdl);
CVMdl = crossval(Mdl);
classError = kfoldLoss(CVMdl);
label = predict(Mdl,features);
% plot confusion(features_test,idx)
% oofLabel = kfoldPredict(CVMdl);
% ConfMat = confusionmat(labels_test,label);
accuracy=confusionmatStats_2(labels_test,label);
% [m,n]=size(label);
%
% count=0;
% for i=1:m
% if(strcmp(labels_test(i),label(i)))
% count=count+1;
% end
% end
% Regards Regards

2 Comments

hai..i am doing the same knn and svm classifier as yours for facial expression recognition. can you teach me how to classify the 7 facial expression and label it by using knn and svm? can i have your email to learn futher from you? thank you
hai fatin and kashif, can you send me the code of emotion recognition to my email syamizalloi@gmail.com.thank you

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!