What must you tell the k-means algorithm before it starts?

The number of clusters, k.

Start playing free

  1. The correct label for each point
  2. The number of clusters to make ✔
  3. The exact coordinates of every centroid

Why: k-means needs k up front. It then places k centroids, assigns each point to the nearest one, moves each centroid to the middle of its points, and repeats.

Huh, didn't know that: It minimizes inertia, the within-cluster sum of squared distances to each centroid.

The dad joke
I asked k-means to organize my sock drawer. It wanted to know how many piles first.
Like this card?
Play the game

References

Answer: The number of clusters to make. k-means needs k up front. It then places k centroids, assigns each point to the nearest one, moves each centroid to the middle of its points, and repeats.

  1. scikit-learn User Guide: Clustering scikit-learn.org/stable/modules/clustering.html
    This algorithm requires the number of clusters to be specified.
    Checked 2026-10-10.

Think this answer is wrong? Tap "Challenge this answer" on the card in the game and tell us why.

Test yourself in the game