How to use fitcknn for multiple classes?
2 次查看(过去 30 天)
显示 更早的评论
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
- How to use fitcknn or any knn classifier to classify
- along with cross-validation
- and find accuracy precision and recall
- 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 个评论
fatin suhana mohd khidzir
2019-4-19
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
Mohd Syamizal Mohd Isa
2020-3-6
hai fatin and kashif, can you send me the code of emotion recognition to my email syamizalloi@gmail.com.thank you
回答(0 个)
另请参阅
类别
在 Help Center 和 File 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!