We want 3 clusters 0 2 4 6 8 10 12 14 16 18 20 0 2 4 6 8 10 weekday visits weekend visits
The café's 25 customers are still here, none of them labeled. We give k-means only the number of clusters: k = 3. The algorithm will stand for each cluster with a centre and put each customer into a cluster.
Random start 0 2 4 6 8 10 12 14 16 18 20 0 2 4 6 8 10 weekday visits weekend visits
3 of the customers were picked at random and became the first centres. The squares are the centres, coloured with their cluster's colour. Because the start is random, another seed starts from other centres and the result can change too.
Each customer to the nearest centre 0 2 4 6 8 10 12 14 16 18 20 0 2 4 6 8 10 weekday visits weekend visits
Each customer took the colour of its nearest centre. The background shows which centre every place on the chart is closest to. Adding up the squared distances of customers to their centres gives 612.0; k-means tries to make this sum small.
Centres move to the mean 0 2 4 6 8 10 12 14 16 18 20 0 2 4 6 8 10 weekday visits weekend visits
Each centre moved to the mean of its own customers; the dashed lines are their paths. The sum is now 327.5. The mean is the point that makes the sum of squares in a cluster smallest, so the sum never goes up. The background changed too: a customer that is now closer to another centre moves to that centre's cluster in the next round.
Round 2 0 2 4 6 8 10 12 14 16 18 20 0 2 4 6 8 10 weekday visits weekend visits
Assignment and update were repeated. 5 customers changed cluster in this round, and the centres moved to the new means. The sum is 142.9.
Round 3 0 2 4 6 8 10 12 14 16 18 20 0 2 4 6 8 10 weekday visits weekend visits
Assignment and update were repeated. 1 customers changed cluster in this round, and the centres moved to the new means. The sum is 92.8.
No assignment changed, k-means stopped 0 2 4 6 8 10 12 14 16 18 20 0 2 4 6 8 10 weekday visits weekend visits
After 3 rounds no customer changed cluster and the algorithm stopped. The sum is 92.8; 20 separate k-means++ starts found no smaller sum. A new customer can be put into a cluster by looking at the nearest centre.