The mechanism of the K-means algorithm can be summarized with the following flowchart:
Let's describe the process in more detail:
We start with the unclassified samples and take K elements as the starting centroids. There are also possible simplifications of this algorithm that take the first element in the element list for the sake of brevity.
We then calculate the distances between the samples and the first chosen samples, and so we get the first calculated centroids (or other representative values). You can see in the moving centroids in the illustration a shift toward a more ...