What is the Difference Between k-Nearest Neighbors and k-Means Clustering?

A simple explanation of the difference between k-NN and k-means.

Vishal Rasadiya
The Startup

--

Photo by Doug Linstedt on Unsplash

Are you confused with the k-Nearest Neighbor (k-NN) and k-means clustering? Let’s try to understand the difference between k-NN and k-means in simple words with examples.

Let me introduce some major differences between them before going to the examples. Don’t worry, I won’t talk much !!

  • k-NN is a supervised machine learning while k-means clustering is an unsupervised machine learning. Yes! You thought it correct, the dataset must be labeled if you want to use k-NN.
  • k-NN is versatile; it can be used for the classification and the regression problems as well. However, it is more widely used in classification problems in the industry. k-means is used for the clustering. But what is clustering?

Clustering is simply grouping the samples of the dataset in such a way that objects in the same group are more similar to each other than to those in other groups.

You can try to group the following into two: monkey, dog, apple, orange, tiger, and banana for better understanding! I am sure you did it right. Let’s move on.

  • k-NN is a lazy learning and non-parametric algorithm…

--

--

Vishal Rasadiya
The Startup

ML/Data Science Enthusiast | Currently Working on Master Thesis