Clustering interview question

Machine LearningClusteringbasic

Which description matches the standard k-means (Lloyd's) algorithm?

  1. AStart with every point as its own cluster, then repeatedly merge the two closest clusters until exactly k clusters remain.
  2. BFit k Gaussian components by alternating between membership probabilities and re-estimating each component's mean and covariance.
  3. CInitialize k centroids, then alternate: assign each point to its nearest centroid and move each centroid to its points' mean.
  4. DMark points with many neighbours within a radius as core points, then grow clusters by linking any core points that lie close together.
Show the answer and explanation

Correct answer: C, Initialize k centroids, then alternate: assign each point to its nearest centroid and move each centroid to its points' mean.

Explanation Clustering

Lloyd's algorithm for k-means:

  1. Choose k initial centroids (randomly or with k-means++).
  2. Assignment step: assign every point to its nearest centroid (squared Euclidean distance).
  3. Update step: move each centroid to the mean of the points assigned to it.
  4. Repeat steps 2–3 until the assignments stop changing (or the centroids move less than a tolerance).

Neither step can increase the within-cluster sum of squares, so the algorithm converges, but only to a local optimum that depends on the starting centroids.

Why the other descriptions are different algorithms:

  • Merging the closest clusters bottom-up is agglomerative hierarchical clustering.
  • Membership probabilities plus covariance updates is EM for a Gaussian mixture model; k-means uses hard assignments and no covariances.
  • Core points and density-based growth describe DBSCAN.

Interview tip: name the two alternating steps (assign, update) and mention right away that the result depends on initialization.

Practice it as a quiz

Answer this and the other free questions with instant grading, streaks and weak-topic tracking, or unlock all 4,000 questions.

More Machine Learning questions

  1. What does precision measure for a binary classifier?
  2. How does k-fold cross-validation work?
  3. How does grid search look for good hyperparameters?
  4. What is the difference between batch gradient descent and stochastic gradient descent (SGD)?
  5. In reinforcement learning vocabulary, what is the reward?