K-Means Clustering Explorer
K-Means partitions data into K clusters by assigning points to the nearest centroid and recomputing centroids until convergence.
Dataset Preview
Currently plotting sepal length (cm) vs sepal width (cm).
| sepal length (cm) | sepal width (cm) | petal length (cm) | petal width (cm) | true_label |
|---|---|---|---|---|
| 5.10 | 3.11 | 1.82 | 0.42 | Species 1 |
| 4.38 | 3.04 | 1.55 | 0.19 | Species 1 |
| 4.99 | 3.16 | 1.87 | 0.39 | Species 1 |
| 5.02 | 3.72 | 1.70 | 0.10 | Species 1 |
| 5.12 | 3.13 | 1.87 | 0.24 | Species 1 |
| 4.94 | 3.21 | 2.01 | 0.22 | Species 1 |
| 4.86 | 3.30 | 1.72 | 0.32 | Species 1 |
| 5.13 | 3.52 | 2.40 | 0.18 | Species 1 |
Elbow Method
WCSS always decreases as K increases. The elbow is where the rate of decrease starts to slow.
Cluster Visualization
Cluster 150 points33.3% of data
Cluster 242 points28.0% of data
Cluster 358 points38.7% of data
WCSS: 85.3 ยท Converged in 6 iterations.
Compare K Values
K = 2
K = 3
K = 4
K = 5
PCA Projection - All Features
PCA projects high-dimensional data into 2D while preserving as much variance as possible.
The two PCA components capture 95.4% of total variance.
K-Means Algorithm
- Initialize K centroids randomly.
- Assign each point to the nearest centroid.
- Update each centroid to the mean of its assigned points.
- Repeat until centroids stop moving.
Scale your features before clustering, run with multiple random starts, and treat the elbow as a heuristic rather than a law.