Value of k in k nearest neighbor algorithm

user574183 picture user574183 · Jul 19, 2012 · Viewed 46.1k times · Source

I have 7 classes that needs to be classified and I have 10 features. Is there a optimal value for k that I need to use in this case or do I have to run the KNN for values of k between 1 and 10 (around 10) and determine the best value with the help of the algorithm itself?

Answer

NominSim picture NominSim · Jul 19, 2012

In addition to the article I posted in the comments there is this one as well that suggests:

Choice of k is very critical – A small value of k means that noise will have a higher influence on the result. A large value make it computationally expensive and kinda defeats the basic philosophy behind KNN (that points that are near might have similar densities or classes ) .A simple approach to select k is set k = n^(1/2).

It's going to depend a lot on your individual cases, sometimes it is best to run through each possible value for k and decide for yourself.