Holger von Jouanne-Diedrich takes us through an example of how k-means clustering works:

The guiding principles are:

– The

distancebetween data points within clusters should be as small as possible.

– The distance of thecentroids(= centres of the clusters) should be as big as possible.Because there are too many possible combinations of all possible clusters comprising all possible data points

k-means follows aniterativeapproach

Click through for a demonstration. I appreciate adding visualizations for intermediate steps in there as well because it gives you an intuitive understanding for what the one-liner function is really doing.