The working of the K-means algorithm

1. Select the number of K (to decide the number of clusters)

2. Select random K points or centroids

3. Assign each data point to their closest centroid

4. Calculate the variance and place a new centroid of each cluster

5. Repeat the third step (which means reassigning each data point to the new closes centroid of each cluster)

6. If any reassignment occurs, then go to step 4; else, go to finish

7. Finish