top of page

K-Means Clustering

A cluster refers to a collection of data points aggregated together because of certain similarities. The objective of K-means is simple: group similar data points together and discover underlying patterns. To achieve this objective, K-means looks for a fixed number (k) of clusters in a dataset. The K-means algorithm identifies k number of centroids, and then allocates every data point to the nearest cluster, while keeping the centroids as small as possible. The ‘means’ in the K-means refers to averaging of the data; that is, finding the centroid.

The way kmeans algorithm works is as follows:

  • Specify number of clusters K.

  • Initialize centroids by first shuffling the dataset and then randomly selecting K data points for the centroids without replacement.

  • Keep iterating until there is no change to the centroids. i.e assignment of data points to clusters isn’t changing.

optimal number of clusters.png

Using ELBOW CURVE to decide on the optimum number of clusters.

To determine the optimal number of clusters, we have to select the value of k at the “elbow” ie the point after which the distortion/inertia start decreasing in a linear fashion. Thus for the given data, we conclude that the optimal number of clusters for the data is 3.

Total WIthin Sum of Squares is given using:-

11ba62446eb2cfeab14b50dcfd685b2e1962a4e2
Histogram
Scatter Plot
Calories, Products and Clusters
cluster_cereals_

© 2020 by Raj Kumar Beniwal. Proudly created with Wix.com

bottom of page