MATLAB Answers

knn classifier function in matlab

6 views (last 30 days)
divya r
divya r on 2 Jul 2012
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.

  0 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 2 Jul 2012
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.

  0 Comments

Sign in to comment.

Sign in to answer this question.