Azzera filtri
Azzera filtri

knn classifier function in matlab

13 visualizzazioni (ultimi 30 giorni)
divya r
divya r il 2 Lug 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.

Risposte (1)

Walter Roberson
Walter Roberson il 2 Lug 2012
k The number of nearest neighbors used in the classification. Default is 1.
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