DEV Community

Cover image for K-Means Clustering

K-Means Clustering

xsabzal profile image Abzal Seitkaziyev ・1 min read

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.

Discussion (0)

Forem Open with the Forem app