# KMeans, level=detailed

Summary: K-means (k = 4, init = k-means++) ran 7 iterations (no label changed). Inertia fell from 851 to 541; 96% of the drop came in the first 2 iterations.

[0] init, iteration 0
- Init: k-means++ seeded the 4 centroids at rows 164, 179, 116 and 280; each seed was the best of 3 candidates sampled with probability proportional to squared distance from the centroids already chosen. Next: assign each point to its nearest centroid.
  (Centroid: the centre of a cluster, at the average position of its points.)
  (K-means++: a way to choose starting centroids that are spread out, which usually means fewer iterations.)

[1] assign, iteration 1
- Assigned all 300 points to their nearest centroid; cluster sizes 60, 98, 71 and 71. Inertia: 851.
  (Inertia: the sum of squared distances from every point to its centroid; lower means tighter clusters.)

[2] update, iteration 1
- Centroid 3 moved 1.53, mostly along feature_1 (-1.09), to the mean of its 71 points.
- Centroid 1 moved 0.745, mostly along feature_0 (-0.563), to the mean of its 98 points.
- Centroids 0 and 2 moved 0.27 and 0.553.
- Inertia 851 → 603 (-29.1%).

[3] assign, iteration 2
- 19 of 300 points (6%) changed cluster, taking inertia 603 → 567 (-6.05%). Largest flow: 8 from cluster 1 to 0; sizes now 67, 84, 72 and 77.

[4] update, iteration 2
- Centroid 1 moved 0.31, mostly along feature_0 (-0.307), because 1 point joined it and 15 points left (now 84 points).
- Centroid 0 moved 0.245, mostly along feature_1 (-0.242), because 9 points joined it and 2 points left (now 67 points).
- Centroids 2 and 3 moved 0.0621 and 0.136.
- Inertia 567 → 553 (-2.43%).

[5] assign, iteration 3
- 8 of 300 points (3%) changed cluster, taking inertia 553 → 547 (-1.16%). Largest flow: 4 from cluster 1 to 0; sizes now 71, 78, 73 and 78.

[6] update, iteration 3
- Centroid 0 moved 0.142, mostly along feature_1 (-0.138), because 5 points joined it and 1 point left (now 71 points).
- Centroid 1 moved 0.126, mostly along feature_0 (-0.126), because 6 points left (now 78 points).
- Centroids 2 and 3 moved 0.0406 and 0.0531.
- Inertia 547 → 544 (-0.548%).

[7] assign, iteration 4
- 3 of 300 points (1%) changed cluster, taking inertia 544 → 543 (-0.124%). Largest flow: 2 from cluster 3 to 0; sizes now 74, 77, 73 and 76.

[8] update, iteration 4
- Centroid 0 moved 0.0604, mostly along feature_1 (-0.0604), because 3 points joined it (now 74 points).
- Centroid 3 moved 0.0516, mostly along feature_1 (-0.0502), because 2 points left (now 76 points).
- Centroids 1 and 2 moved 0.0211 and 0.
- Inertia 543 → 542 (-0.0932%).

[9] assign, iteration 5
- 3 of 300 points (1%) changed cluster, taking inertia 542.4 → 541.8 (-0.105%). Largest flow: 2 from cluster 1 to 0; sizes now 77, 75, 73 and 75.

[10] update, iteration 5
- Centroid 0 moved 0.061, mostly along feature_1 (-0.0519), because 3 points joined it (now 77 points).
- Centroid 1 moved 0.0417, mostly along feature_0 (-0.036), because 2 points left (now 75 points).
- Centroids 2 and 3 moved 0 and 0.028.
- Inertia 542 → 541 (-0.0877%).

[11] assign, iteration 6
- 2 of 300 points (1%) changed cluster, taking inertia 541.3 → 541.2 (-0.0216%). Largest flow: 1 from cluster 0 to 2; sizes now 77, 74, 74 and 75.

[12] update, iteration 6
- Centroid 0 moved 0.0291, mostly along feature_1 (-0.0284), because 1 point joined it and 1 point left (now 77 points).
- Centroid 2 moved 0.0271, mostly along feature_1 (-0.0208), because 1 point joined it (now 74 points).
- Centroids 1 and 3 moved 0.0218 and 0.
- Inertia 541.2 → 541.1 (-0.0285%).

[13] assign, iteration 7
- 0 of 300 points changed cluster; inertia unchanged at 541.

[14] update, iteration 7
- None of the 4 centroids moved, because no point joined or left any cluster.
- Inertia unchanged at 541.

[15] done, iteration 7
- Converged after 7 iterations: no label changed in the last one. Final inertia 541.
  (Iteration: one assignment pass followed by one update pass.)

Diagnostics: none
