What is K-Means Clustering and how does it work?

Updated May 16, 2026

Short answer

K-Means is an unsupervised learning algorithm that partitions data into K clusters by minimizing distance between points and cluster centroids.

Deep explanation

K-Means works by iteratively assigning data points to the nearest centroid and then recomputing centroids as the mean of assigned points. The objective is to minimize within-cluster sum of squared distances (WCSS). It converges when assignments stop changing or centroids stabilize.

Real-world example

Customer segmentation in marketing based on purchasing behavior.

Common mistakes

  • Assuming clusters are always spherical or equal-sized.

Follow-up questions

  • Is K-Means supervised or unsupervised?
  • What does K represent?

More K-Means Clustering interview questions

View all →