K-Means Clustering (2D) — Lloyd's Algorithm
Interactive 2D k-means: assign every point to its nearest centroid, move each centroid to the mean of the points assigned to it, and repeat. Watch the Voronoi cells settle and inertia fall, with k-means++ seeding, a k slider and Blobs/Moons/Random data presets.
This 2D companion runs the same Lloyd's-algorithm loop as the 3D version on a plain canvas: click to add points, pick a k, and watch the two-step iteration — assign every point to its nearest centroid, then move each centroid to the mean of its assigned points — carve the plane into Voronoi cells that settle as inertia (the sum of squared distances from each point to its centroid) falls. A k-means++ toggle lets you compare seeding strategies, and the Blobs/Moons preset makes clear where k-means succeeds (round, similarly-sized clusters) and where it struggles (the interleaving Moons shapes).
Interactive 2D k-means: assign each point to its nearest centroid, move centroids to the mean, repeat. Watch the Voronoi cells settle and inertia drop, with k-means++ seeding and Blobs/Moons/Random presets.
2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install