Why is k-means typically run multiple times with different initialisations, and how is the final solution chosen?

Last updated 11 November 2026

Lloyd's algorithm only converges to a local minimum that depends on the starting centroids, so you run it several times from different seeds and keep the run with the lowest within-cluster sum of squares (inertia).

  • Why restarts are needed:

    • The objective is non-convex; bad seeds can put two centroids in one true cluster and one centroid spanning two clusters.

    • Lloyd's steps can't escape that configuration since each step only decreases cost locally.

  • How the final solution is chosen:

    • Compare runs by the objective itself (inertia), for the same k; pick the minimum.

    • In scikit-learn this is n_init: the best run's inertia_ is kept.

    • Inertia is valid here because k is fixed; it can't compare different k.

  • Interaction with k-means++: Smarter seeding reduces the number of restarts needed but doesn't eliminate variance.

  • Bonus diagnostic: if different runs give very different partitions with similar inertia, the cluster structure is weak or k is wrong.

  • https://apxml.com/courses/introduction-to-machine-learning/chapter-5-unsupervised-learning-clustering/limitations-of-k-means
  • https://apxml.com/courses/applied-data-science/chapter-4-applied-unsupervised-learning/implementing-kmeans
  • https://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html
All Clustering interview questions