← All notes · ML revision (DA5400)

Clusters in 3D

The same three generating processes as the 2-D experiments, with a third coordinate added (300 points each). Colours are K-means assignments (K-means++, 10 restarts); diamonds mark the cluster means. Drag to rotate, use the toolbar (top right of each plot) to zoom or reset, and hover for coordinates.

Generation: blobs are x = c + σ·ε with ε ~ N(0, I₃). Clear clusters: σ = 0.6, centres on 4 vertices of a cube, so all are 8.5 apart. Nested: 3 groups 10–12 apart, each split into 2 subgroups 2.4 apart along x, σ = 0.35. Uniform: points spread evenly over the cube [0, 10]³.

Elbow method: how the cost falls with K

For each K from 1 to 10, Lloyd's algorithm was run with K-means++ and 10 restarts, keeping the lowest cost F*(K) = Σ‖xᵢ − μzᵢ‖². The cost always falls as K grows. The elbow is where it suddenly stops falling much: the next drop is less than 20% of this one. Circles mark the elbows.

Lloyd's algorithm: random starts vs K-means++

K-means++ isn't a separate algorithm: it's a smarter starting point for Lloyd's. Each start below was run 200 times as a single run (no restarts) at the true K. Each dot is one run's final cost; the dashed line is the best cost any run found. On the first two datasets the cost axis is logarithmic.

Random partitionPut each point into a random cluster, then compute means.
Random pointsUse K random data points as the starting means.
K-means++First mean at random; each next mean sampled with probability ∝ D(x)², the squared distance to the nearest mean so far.

ARI (adjusted Rand index) measures agreement with the true groups: 1 is perfect, 0 is no better than chance. It isn't defined for the uniform data, which has no true groups.