Statistics

K-Means Simulator

Explore how K-Means clusters points step by step and learn when it works and when it fails.

Points: 0K: 3Ready

Interactive plane

Click on the plane to add points manually.

Click to add points
Active clusters
Cluster 1
Cluster 2
Cluster 3

Execution mode

Step 1 · Initialization

Configurable parameters

K-Means++ spreads centroids to improve convergence.

Realtime status

Iteration0
Total centroid shift0
Inertia (WCSS)0
StateReady

Point generation

Populate the plane with clicks, presets, or random data.

Manual clicks.Each click adds one point to the plane.

Demonstrated limitations

Examples where K-Means fails or becomes unstable.

Try different seeds to see different outcomes.

How many clusters?

Run K-Means for K=2..8 and look for the elbow in inertia.


About this tool

Clustering is an unsupervised learning task whose goal is to discover structure in data by grouping similar observations together. K-Means minimizes the inertia or within-cluster sum of squared distances: J=∑k=1K∑xi∈Ck∥xi−μk∥2J = \sum_{k=1}^{K}\sum_{x_i \in C_k} \|x_i - \mu_k\|^2 where μk\mu_k is the centroid of cluster kk. Although the exact minimization problem is NP-hard, Lloyd's algorithm finds local solutions efficiently.

The algorithm works iteratively: it initializes KK centroids, assigns each point to the nearest centroid k^(xi)=arg⁡min⁡k∥xi−μk∥2\hat{k}(x_i) = \arg\min_k \|x_i - \mu_k\|^2, and recalculates centroids as the mean of assigned points. This process guarantees that JJ decreases or stays the same at each iteration until convergence. The K-Means++ initialization improves solution quality by choosing initial centroids with probability proportional to their distance from the nearest already-chosen centroid.

This tool visualizes the algorithm step by step. Experiment with different values of KK, different initializations, and different point distributions to understand when K-Means works well and when it fails: with non-convex cluster shapes or very different densities.