Home▸Machine Learning & Neural Networks▸K-Means Clustering (2D) — Lloyd's Algorithm

🎯 K-Means Clustering (2D) — Lloyd's Algorithm

A 2D canvas simulation showing k-means clustering: points are assigned to the nearest centroid and centroids move to the cluster mean until the assignment stops changing.

Machine Learning & Neural Networks2DModerate60 FPS📱 Mobile-adapted⇄ 3D version
K-Means Clustering (2D) — Lloyd's Algorithm ↗ Open standalone

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).

⚙ Under the hood

A 2D canvas simulation showing k-means clustering: points are assigned to the nearest centroid and centroids move to the cluster mean until the assignment stops changing.

k-meansclusteringlloyd's algorithmunsupervisedvoronoicanvas 2d

2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)