output as outputwe will get following image showing clusters centers learned by -means the following lines of code will match the learned cluster labels with the true labels found in themfrom scipy stats import mode labels np zeros_like(clustersfor in range( )mask (clusters =ilabels[maskmode(digits target[mask])[ nextwe can check the accuracy as followsfrom sklearn metrics import accuracy_score accuracy_score(digits targetlabelsoutput the above output shows that the accuracy is around advantages and disadvantages advantages the following are some advantages of -means clustering algorithmsit is very easy to understand and implement if we have large number of variables thenk-means would be faster than hierarchical clustering on re-computation of centroidsan instance can change the cluster tighter clusters are formed with -means as compared to hierarchical clustering disadvantages