knn classifier function in matlab

5 ビュー (過去 30 日間)
divya r
divya r 2012 年 7 月 2 日
In the function knnclassify(sample,training,group,k), what is the purpose of k?
I havent completely understood the explanation of the function i think.I have tried varying it but the output is always the same.
I know this is a very silly doubt i am asking, but i am just not getting it.

回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 7 月 2 日
k The number of nearest neighbors used in the classification. Default is 1.
and
The default behavior is to use majority rule. That is, a sample point is assigned to the class the majority of the k nearest neighbors are from. Use 'consensus' to require a consensus, as opposed to majority rule. When using the 'consensus' option, points where not all of the k nearest neighbors are from the same class are not assigned to one of the classes. Instead the output Class for these points is NaN for numerical groups or '' for string named groups.
In other words, when you did your testing, the results were the same when you varied k because the majority of neighbors happened to agree with the first nearest neighbor. This can, for example, happen if your clusters do not overlap much.

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by