# KMeans, level=beginner

Summary: K-means settled in 7 iterations; 95% of the drop in inertia happened in the first 2 iterations.

[0] init, iteration 0
- The 3 starting centroids are the positions you passed as init. Next, every point will join its nearest centroid.
  (Centroid: the centre of a cluster, at the average position of its points.)

[1] assign, iteration 1
- Every point joined its nearest centroid, giving clusters of 42, 78 and 0 points. The inertia starts at 3,620.
  (Inertia: the sum of squared distances from every point to its centroid; lower means tighter clusters.)

[2] update, iteration 1
- Cluster 2 lost all its points, so its centroid jumped onto the point farthest from its own centroid (row 114, taken from cluster 1) to keep every cluster in use.
- Centroid 1 moved down and to the left to the middle of its 77 points.
- Centroid 0 moved less (1.6).
- Together these moves lowered the inertia from 3,620 to 1,586.

[3] assign, iteration 2
- 63 points switched to a closer centroid, so the inertia fell from 1,586 to 639. The biggest move was 36 points from cluster 1 to cluster 2.

[4] update, iteration 2
- Centroid 1 moved up and to the right by 2.19 because 63 points left, so the average of its points changed.
- Centroid 2 moved up and to the right by 1.38 because 36 points joined it, so the average of its points changed.
- Centroid 0 moved less (1.16).
- Together these moves lowered the inertia from 639 to 409.

[5] assign, iteration 3
- 7 points switched to a closer centroid, so the inertia fell from 409 to 365. The biggest move was 4 points from cluster 0 to cluster 1.

[6] update, iteration 3
- Centroid 1 moved up and to the right by 1.42 because 4 points joined it and 3 points left, so the average of its points changed.
- Centroid 2 moved up and to the right by 0.179 because 3 points joined it, so the average of its points changed.
- Centroid 0 moved less (0.164).
- Together these moves lowered the inertia from 365 to 332.

[7] assign, iteration 4
- 17 points switched to a closer centroid, so the inertia fell from 332 to 291. The biggest move was 17 points from cluster 0 to cluster 1.

[8] update, iteration 4
- Centroid 0 moved up by 0.704 because 17 points left, so the average of its points changed.
- Centroid 1 moved up by 0.663 because 17 points joined it, so the average of its points changed.
- Centroid 2 kept the same points, so it stayed put.
- Together these moves lowered the inertia from 291 to 253.

[9] assign, iteration 5
- 6 points switched to a closer centroid, so the inertia fell from 253 to 236. The biggest move was 6 points from cluster 0 to cluster 1.

[10] update, iteration 5
- Centroid 0 moved up by 0.297 because 6 points left, so the average of its points changed.
- Centroid 1 moved up by 0.191 because 6 points joined it, so the average of its points changed.
- Centroid 2 kept the same points, so it stayed put.
- Together these moves lowered the inertia from 236 to 231.

[11] assign, iteration 6
- 2 points switched to a closer centroid, so the inertia fell from 231 to 229. The biggest move was 2 points from cluster 0 to cluster 1.

[12] update, iteration 6
- Centroid 0 moved up and to the right by 0.0982 because 2 points left, so the average of its points changed.
- Centroid 1 moved up and to the left by 0.0865 because 2 points joined it, so the average of its points changed.
- Centroid 2 kept the same points, so it stayed put.
- Together these moves lowered the inertia from 229.3 to 228.6.

[13] assign, iteration 7
- No point changed cluster: each one is already with its nearest centroid. The inertia stays at 229.

[14] update, iteration 7
- None of the 3 centroids moved, because no point joined or left any cluster.
- The inertia stayed at 229.

[15] done, iteration 7
- K-means stopped after 7 iterations because no point changed cluster, so another round would change nothing. The final inertia is 229.
  (Iteration: one assignment pass followed by one update pass.)

Diagnostics:
- [step 2] Cluster 2 lost all its points in iteration 1, so its centroid had to be moved.
  Fix: Empty clusters usually mean poor starting centroids or too many clusters: try init='k-means++', more restarts (n_init=10) or a smaller n_clusters.
