How does the k-means clustering algorithm group unlabelled data points into k clusters, and what happens in one full iteration on the 1-D (one-dimensional) points {0,2,8,10} with k=2 starting from initial centres 2 and 6?

Unsupervised learning, Clustering
Level L1 Beginner. Length Short. Nature Th+Mat Both.

What's being asked

Whether you know the basic two-step loop of k-means (assign points, update means) before studying convergence, k-means++ or choosing k.

Key idea

After picking k starting centres (centroids), k-means repeats two steps until nothing changes: assign every point to its nearest centre, then move each centre to the average (mean) of the points assigned to it.

Steps

  1. Initialise k cluster centres: here k=2, with starting centres c1=2 and c2=6.
  2. Assign step (cluster points by nearest centre): compare distances to 2 and 6. Points 0 and 2 are closer to 2 (distances 2 and 0, vs 6 and 4), while 8 and 10 are closer to 6 (distances 2 and 4, vs 6 and 8). This gives clusters {0,2} and {8,10}.
  3. Update step (recompute each centre as its cluster mean): c1=(0+2)/2=1 and c2=(8+10)/2=9. Moving the centre to the mean minimises squared distances inside that cluster.
  4. Check stopping: on the next pass, 0 and 2 stay closest to 1 and 8 and 10 stay closest to 9, so no points switch clusters and the algorithm stops with centres 1 and 9.

Common mistakes

How long your answer should be

Under 2 minutes: state the assign/update loop and walk through the 4-point trace.

Read this

Previous in Unsupervised learning: In clustering we group points that are "close" to each other. How do we measure closeness with the Euclidean (straight-line) distance, and what is it between the points (1,2) and (4,6)?
Next in Unsupervised learning: What does principal component analysis (PCA) do to a dataset, what are principal components geometrically, and why do we often keep only the first few?