Can K-nearest neighbor classify more than two classes?

I want to know that K-nearest neighbor classifier can classify more than two classes? I don't understand much about this classifier.

3 件のコメント

Jan
Jan 2017 年 12 月 17 日
In general "knn" methods are able to find more than 2 classes. A look into a textbook, your script, WikiPedia of the Matlab documentation should help you to learn more about this topic. If a detail about Matlab is not clear to you, please ask specifically, otherwise answering is hard.
gugu
gugu 2017 年 12 月 18 日
Ok. I'll have a go at it. Actually, I want to classify three classes and now I'm currently using multi-svm. It doesn't meet my requirements. So, I want to change the classifier. Thank you for your answer.
Ehsan Altayef
Ehsan Altayef 2020 年 4 月 20 日
i need knn algorithm code, please anyone has could you send it to me on Tripoli201919@gmail.com.Thank you in advance.

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

回答 (1 件)

the cyclist
the cyclist 2017 年 12 月 17 日

0 投票

Yes, it can. There is an example of a 3-class classification in the documentation for fitcknn, in the Statistics and Machine Learning Toolbox.
load fisheriris
X = meas;
Y = species;
% X is a numeric matrix that contains four petal measurements for 150 irises.
% Y is a cell array of character vectors that contains the corresponding iris species.
% Train a 5-nearest neighbors classifier. It is good practice to standardize noncategorical predictor data.
Mdl = fitcknn(X,Y,'NumNeighbors',5,'Standardize',1)

4 件のコメント

gugu
gugu 2017 年 12 月 18 日
Thanks for your answer.
gugu
gugu 2017 年 12 月 18 日
Let me ask you one question. Does the result of the classifier depend on the number of training data? I mean the larger the training data, the better the result. Is that so?
Image Analyst
Image Analyst 2017 年 12 月 18 日
Not necessarily. Denser data may make it more accurate, but just expanding the feature space so that it's bigger will not affect the results. For example if you had 500 training points in the range x=4-5, and y = 4-5, and you increased it to 2000 training points in that same area would make it more accurate. However if you still had 500 points there and just added another few thousand points in the range 0-10 in both x and y, would not necessarily make your classifications in the range 4-5 any better than what they were, since it would be using the same points as before.
gugu
gugu 2017 年 12 月 18 日
It's clear on my mind. Thank you so much.

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

質問済み:

2017 年 12 月 17 日

コメント済み:

2020 年 4 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by