/  Top Machine learning interview questions and answers   /  What is K in KNN classifier and How to choose optimal value of K?
KNN-classifier-2-i2tutorials

What is K in KNN classifier and How to choose optimal value of K?

To select the K for your data, we run the KNN algorithm several times with different values of K and choose the K which reduces the number of errors we meet while maintaining the algorithm’s ability to accurately make predictions.

As we decrease the value of K to 1, our predictions become less stable.

Inversely, as we increase the value of K, our predictions become more stable due to majority averaging, and thus, more likely to make more accurate predictions. Eventually, we begin to witness an increasing number of errors.

In cases where we are taking a majority vote among labels, we usually make K an odd number to have a tiebreaker.

Leave a comment