Home▸AI & Machine Learning▸2D K-Means Clustering Visualiser

📊 2D K-Means Clustering Visualiser

Click to place points or generate blobs, then watch a real 2D K-Means algorithm run: centroid init, nearest-centroid assignment, mean-update, live convergence detection, and a real elbow plot.

AI & Machine Learning2DModerate60 FPS📱 Mobile-adapted⇄ 3D version
2d-kmeans ↗ Open standalone

About the 2D K-Means Visualiser

This is a from-scratch, flat 2D companion to the 3D K-Means simulation. Click anywhere on the canvas to drop a data point, or generate a random blob dataset, then step through — or run to convergence — a real Lloyd's-algorithm K-Means implementation: centroid initialisation, nearest-centroid assignment by squared Euclidean distance, and mean-recompute centroid updates, repeated until assignments stop changing.

The sidebar's Elbow Method panel is not decorative: it actually re-runs K-Means from scratch for every K from 2 to 8 on the current dataset and plots the resulting within-cluster sum of squares (WCSS), so the bend in the bars reflects a genuine computation rather than a canned curve.

Frequently Asked Questions

How is this different from the 3D version?

Same algorithm, flat 2D canvas rendering instead of a WebGL/Three.js scene — lighter weight, and the cluster regions are drawn as a simple 2D nearest-centroid tint rather than a shader-based Voronoi field.

Is the elbow chart real?

Yes. Pressing Generate Blobs (or clicking points) recomputes it by running an independent, full K-Means to convergence for each K from 2 to 8 and recording the final WCSS — nothing is precomputed or faked.

What does convergence mean here?

The algorithm stops automatically the moment no point's cluster assignment changes between one iteration and the next — the mathematical definition of convergence for Lloyd's algorithm, not a fixed iteration count.

⚙ Under the hood

Click to place data points or generate random blobs, then watch a real 2D K-Means algorithm run: genuine centroid initialisation, nearest-centroid assignment by Euclidean distance, mean-recompute centroid updates, live convergence detection, and a real elbow-method plot computed by re-running K-Means at every K.

machine-learningclusteringk-meansunsupervised-learningdata-sciencealgorithm

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

What did you find?

Add reproduction steps (optional)