K-Means vs K-Nearest Neighbors

We have already seen K-Means, Let’s see it’s neighbor  K-Nearest Neighbors

K-Means and K-Nearest Neighbors(KNN) use similar algorithms, their prediction and use cases are different and they fall in different category of ML, that is Unsupervised and Supervised respectively.

K-Means is used for clustering, given a set of data, K-Means clusters them into K clusters. 

 KNN is used for Classification and Regression, that is classify a new data point into a nearest to the K data points, to say in terms of algorithm,

  • Take the least squared distances of the data set,
  • Sort them in ascending order  and
  • Take top K data points, find out the majority of classes 
  • In case of Regression, take the mean of K data points

We can see it’s different from the K-Means, though it uses same Least Squared for computing.

Use Cases

  • Recommender Systems, for example based on user purchased items we can recommend similar items
  • Classify documents , aka Text Classification, we can find similar documents

That’s all one need to know..