DEV Community

Cover image for K-Means Clustering
Abzal Seitkaziyev
Abzal Seitkaziyev

Posted on

K-Means Clustering

K-Means clustering is unsupervised algorithm, which is very intuitive and could be visualized geometrically.
Basically, we are trying to split the data into the k groups or clusters, and each cluster has a center, which is defined by calculating geometrical centroid of the cluster.

Steps of the K-means clustering algorithm:

1) Set k initial centers randomly
Alt Text
2) Calculate 'distances'(e.g., if in 2d space) from the data point to these centers and group the data by the 'closest' distances to these centers
Alt Text
3) Recalculate position of k centers (as a mean of the data in that cluster)
Alt Text
4) repeat steps 2 and 3 until no changes.
Alt Text
Alt Text

Here is the link I used to play and visualize clustering.

Top comments (1)

Collapse
 
rohit254 profile image
Rohit Kumar

I also write a blog on K-Means clustering please visit it and provide me your valuable thoughts: - K-Means