K-means clustering algorithm computes the centroids and iterates until we it finds optimal centroid.
•First, we need to specify the number of clusters, K, need to be generated by this algorithm.
•Next, randomly select K data points and assign each data point to a cluster. In simple words,
•classify the data based on the number of data points.
•Now it will compute the cluster centroids.
•Next, keep iterating the following until we find optimal centroid which is the assignment of data points to the clusters that are not changing any more
•First, the sum of squared distance between data points and centroids would be computed.
•Now, we have to assign each data point to the cluster that is closer than other cluster (centroid).
•At last compute the centroids for the clusters by taking the average of all data points of that cluster.