Whose my nearest neighbor? — source pixabay.com

Today we will understand the k-Nearest Neighbor (kNN) classification algorithm. It is one of the most easiest algorithms.

#100DaysOfMLCode #100ProjectsInML

  • Let’s say we have identified 2 categories in our dataset — say “Red Category 1” and “Green Category 2” as shown below.
image source: A-Z Machine Learning Udemy
  • Now let’s say we add a new data point in our dataset as shown below. So the question is — does it belong to “Red Category 1” or “Green Category 2”. How do we classify this new data point?
image source: A-Z Machine Learning Udemy

So this is where the k Nearest Neighbor (kNN) algorithm will come in to assist us. It’s a very simple algorithm.

  • First we have to decide on the number of k neighbors — the most common or default value for k is 5.
  • Next, we need to find the 5 nearest neighbors to this new data point based on Euclidean distance or Manhattan distance or any other. In layman’s terms, we have to find the 5 data points that are closest…

--

--

Omair Aasim
Analytics Vidhya

Passionate about building products — An advocate of AI, a software engineer by profession — an entrepreneur at heart and a sports enthusiast.