K-Means Clustering Explorer

K-Means partitions data into K clusters by assigning points to the nearest centroid and recomputing centroids until convergence.

Controls

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.

Elbow Method0.32.95.58.110.72.082.0162.0242.1322.1Number of clusters (K)WCSS (inertia)

Cluster Visualization

K-Means with K = 34.15.05.86.67.51.92.53.03.54.0sepal length (cm)sepal width (cm)012
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 = 24.15.05.86.67.51.92.53.03.54.0sepal length (cm)sepal width (cm)

K = 3

K = 34.15.05.86.67.51.92.53.03.54.0sepal length (cm)sepal width (cm)

K = 4

K = 44.15.05.86.67.51.92.53.03.54.0sepal length (cm)sepal width (cm)

K = 5

K = 54.15.05.86.67.51.92.53.03.54.0sepal length (cm)sepal width (cm)

PCA Projection - All Features

PCA projects high-dimensional data into 2D while preserving as much variance as possible.

K-Means labels (K=3)-3.6-1.9-0.21.53.1-2.6-1.3-0.01.32.5PC1PC2012
True labels-3.6-1.9-0.21.53.1-2.6-1.3-0.01.32.5PC1PC2Species 1Species 2Species 3

The two PCA components capture 95.4% of total variance.

K-Means Algorithm

  1. Initialize K centroids randomly.
  2. Assign each point to the nearest centroid.
  3. Update each centroid to the mean of its assigned points.
  4. 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.