train and test data using KNN classifier

23 ビュー (過去 30 日間)
sehrish
sehrish 2013 年 7 月 18 日
コメント済み: Kathryn Hollowood 2019 年 3 月 12 日
HI I want to know how to train and test data using KNN classifier we cross validate data by 10 fold cross validation. there are different commands like KNNclassify or KNNclassification.Fit. Don't know how to accomplish task Plz help me Thanks
  1 件のコメント
Kathryn Hollowood
Kathryn Hollowood 2019 年 3 月 12 日
That he just shared also includes information about predicting the classification using knn. So you use the fitcknn to create the model (Mdl). So it would be like:
class = predict(Mdl, TestCase).
This should hopefully give you what you are looking for.

サインインしてコメントする。

採用された回答

Shashank Prasanna
Shashank Prasanna 2013 年 7 月 18 日
Have you tried out the examples in the documentation?
I don't think we can help you any better than the examples in the doc. If you have specific questions then we can address that.
  1 件のコメント
sehrish
sehrish 2013 年 7 月 19 日
編集済み: sehrish 2013 年 7 月 19 日
Yes Shashank I have tried it but I could not understand where are its training and testing results? here is the code
% Classify the fisheriris data with a K-Nearest Neighbor classifier
load fisheriris
c = knnclassify(meas,meas,species,4,'euclidean','Consensus');
cp = classperf(species,c)
get(cp)
% 10-fold cross-validation on the fisheriris data using linear
% discriminant analysis and the third column as only feature for
% classification
load fisheriris
indices = crossvalind('Kfold',species,10);
cp = classperf(species); % initializes the CP object
for i = 1:10 test = (indices == i); train = ~test;
class = classify(meas(test,3),meas(train,3),species(train));
% updates the CP object with the current classification results
classperf(cp,class,test)
end
cp.CorrectRate % queries for the correct classification rate

サインインしてコメントする。

その他の回答 (1 件)

snehal jaipurkar
snehal jaipurkar 2018 年 1 月 26 日
Sir please reply soon.... can we use eucledian distance and hamming distance both in knn classifier at the same time??? I am working on a project where I have to classify gabor features using hamming distance and geometrical features using eucledian distance..... Is it possible sir?????

Community Treasure Hunt

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

Start Hunting!

Translated by