How does the k-means clustering algorithm group unlabelled data points into clusters, and what happens in one full iteration on the 1-D (one-dimensional) points with starting from initial centres and ?
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 .
Key idea
After picking 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
- Initialise cluster centres: here , with starting centres and .
- Assign step (cluster points by nearest centre): compare distances to and . Points and are closer to (distances and , vs and ), while and are closer to (distances and , vs and ). This gives clusters and .
- Update step (recompute each centre as its cluster mean): and . Moving the centre to the mean minimises squared distances inside that cluster.
- Check stopping: on the next pass, and stay closest to and and stay closest to , so no points switch clusters and the algorithm stops with centres and .
Common mistakes
- Thinking k-means learns the number of clusters automatically; you must choose in advance.
- Assuming a cluster centre must be one of the original data points; the mean (here and ) usually sits between data points, unlike k-medoids.
- Forgetting that poor random starting centres can trap k-means in a bad grouping, which is why practitioners run it several times or use k-means++.
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 and ?
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?