📊 2D K-Means Clustering AI / Machine Learning 🎯 3D version
Configuration
Number of clusters K
3
Show cluster regions
Show centroid paths
Animate step-by-step
Actions
Status
Points0
Iteration0
WCSS—
Converged—
Elbow Method
Legend
K-Means: Assign each point to the nearest centroid by Euclidean distance, then move each centroid to the mean of its assigned points. Repeat until nothing changes.

Elbow Method: Runs full K-Means at every K from 2 to 8 and plots the resulting WCSS — the "elbow" bend suggests a good K.

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.