How KNN algorithm works

1.2K    Asked by CelinaLagunas in Data Science , Asked on Dec 17, 2019
Answered by Celina Lagunas

KNN or K Nearest Neighbor is a non parametric or lazy learning algorithm which works while testing the data. It memorizes the unseen test data by comparing the observation with nearest training observations which are also time consuming while testing each data point.

The accuracy of this algorithm depends on the value of k set to compare the data points to classify the test data.

KNN can be explained with the prediction of voter based on geo location of nearest neighbor. Let us take the value of k=5 and see how it performs


In this algorithm, KNN predicts that the party will vote for party 2 because 3 votes are selected by the algorithm within the neighbor. Only 1 vote is selected by Party 1 and Party 3. In this way, the vote will be predicted for Party 2 and this is how KNN works.


Your Answer

Interviews

Parent Categories