clustering algorithms -means algorithm introduction to -means algorithm -means clustering algorithm computes the centroids and iterates until we it finds optimal centroid it assumes that the number of clusters are already known it is also called flat clustering algorithm the number of clusters identified from data by algorithm is represented by 'kin -means in this algorithmthe data points are assigned to cluster in such manner that the sum of the squared distance between the data points and centroid would be minimum it is to be understood that less variation within the clusters will lead to more similar data points within same cluster working of -means algorithm we can understand the working of -means clustering algorithm with the help of following stepsstep firstwe need to specify the number of clusterskneed to be generated by this algorithm step nextrandomly select data points and assign each data point to cluster in simple wordsclassify the data based on the number of data points step now it will compute the cluster centroids step nextkeep iterating the following until we find optimal centroid which is the assignment of data points to the clusters that are not changing any more firstthe sum of squared distance between data points and centroids would be computed nowwe 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 -means follows expectation-maximization approach to solve the problem the expectation-step is used for assigning the data points to the closest cluster and the maximization-step is used for computing the centroid of each cluster while working with -means algorithm we need to take care of the following thingswhile working with clustering algorithms including -meansit is recommended to standardize the data because such algorithms use distance-based measurement to determine the similarity between data points