Statistics
K-Means Simulator
Explore how K-Means clusters points step by step and learn when it works and when it fails.
Interactive plane
Click on the plane to add points manually.
Execution mode
Configurable parameters
K-Means++ spreads centroids to improve convergence.
Realtime status
Point generation
Populate the plane with clicks, presets, or random data.
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: where is the centroid of cluster . Although the exact minimization problem is NP-hard, Lloyd's algorithm finds local solutions efficiently.
The algorithm works iteratively: it initializes centroids, assigns each point to the nearest centroid , and recalculates centroids as the mean of assigned points. This process guarantees that 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 , 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.
Articles published on the blog
- Cómo funciona k-means e implementación en Python
- Método del codo (Elbow method) para seleccionar el número óptimo de clústeres en K-means
- Identificar el número de clústeres con Calinski-Harabasz en k-means e implementación en Python
- Número óptimo de clústeres con Silhouette e implementación en Python
- El índice de Davies-Bouldinen para estimar los clústeres en k-means e implementación en Python
- Método del codo: interpretación correcta y limitaciones
