How does Lloyd's algorithm for k-means work step-by-step?

Quick Overview

Asks you to walk through Lloyd's algorithm for k-means one step at a time. Tests understanding of initialization, the assignment and update steps, convergence to a local minimum, empty clusters and per-iteration cost.

How does Lloyd's algorithm for k-means work step-by-step?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: easy

Interview Round: Other

How does Lloyd's algorithm for k-means work step-by-step? Lloyd's algorithm is the standard way to fit k-means: given $n$ points in $d$ dimensions and a number of clusters $k$, it searches for centroids that minimize the within-cluster sum of squares. ```hint Two subproblems Split the objective into two easier problems: one where the centroids are held fixed, and one where the cluster memberships are held fixed. What is the best move in each? ``` ### What a Strong Answer Covers - How the centroids are initialized - The assignment step and the update step, and why each one is optimal given the other - The stopping rule and how empty clusters are handled - Convergence: whether it is guaranteed, and to what kind of solution - Cost per iteration ### Follow-up Questions - How does k-means++ choose its initial centroids, and why does it help? - Why is the mean the right update for squared Euclidean distance, and what would you use with Manhattan distance? - How would you run k-means on a dataset that does not fit in memory? - How would you choose $k$?

Overview: Asks you to walk through Lloyd's algorithm for k-means one step at a time. Tests understanding of initialization, the assignment and update steps, convergence to a local minimum, empty clusters and per-iteration cost.

General logo
General
Nov 24, 2026
easyMachine Learning EngineerOtherMachine Learning
0
0

How does Lloyd's algorithm for k-means work step-by-step?

Lloyd's algorithm is the standard way to fit k-means: given nn points in dd dimensions and a number of clusters kk, it searches for centroids that minimize the within-cluster sum of squares.

What a Strong Answer Covers Guidance

  • How the centroids are initialized
  • The assignment step and the update step, and why each one is optimal given the other
  • The stopping rule and how empty clusters are handled
  • Convergence: whether it is guaranteed, and to what kind of solution
  • Cost per iteration

Follow-up Questions Guidance

  • How does k-means++ choose its initial centroids, and why does it help?
  • Why is the mean the right update for squared Euclidean distance, and what would you use with Manhattan distance?
  • How would you run k-means on a dataset that does not fit in memory?
  • How would you choose kk ?