user2490712
user2490712

Reputation: 135

how to determine k value for the k nearest neighbours algorithm for a matrix in matlab

If we have a matrix for 6 rows and 10 columns we have to determine the k value.If we assume default k value is 5 and if we have less columns than 5 with same number of rows 6 can we assume that number of columns=k value is it correct?i.e rows=6 cols=4 then k=col-1 => k=3

Upvotes: 3

Views: 9995

Answers (3)

anilkay
anilkay

Reputation: 144

k=sqrt(n) has not optimal result with the various dataset. Some dataset, its result is quite awful. For example, one paper for 90's paper link says the best result of k is between 5-10 bu sqrt(n) gives us a 17. Some other papers suggest interesting suggestions such as local k value or weighted k.

       İt's obvious choose k it's not an easy choice. That does not have an easy formula for these and depends on our dataset. Best way to choose optimal k is calculate accuracy of which k is best for our dataset. Generally, if our dataset is getting bigger, optimal k value is also increasing.

Upvotes: 0

user776193
user776193

Reputation: 115

k=n^(1/2)

Where n is number of instances and not features. reference 1 , reference 2

Upvotes: 7

discipulus
discipulus

Reputation: 2715

Check this question, value of k in k nearest neighbour algorithm

Same as the previous one. Usually, the rule of thumb is squareroot of number of features

k=n^(1/2)

where n is the number of features. In your case square-root of 10 is approximately 3, so the answer should be 3.

Upvotes: 3

Related Questions