ML0057 K-means

Please explain how K-means works.

Answer

K-means is an iterative unsupervised algorithm that partitions data into K clusters by minimizing intra-cluster distances (within-cluster variance). It alternates between assigning points to the nearest centroid and recomputing centroids until convergence. It is fast and easy to implement, but sensitive to initialization and to non-convex cluster shapes.

(1) Initialization: Choose K initial centroids (randomly, or with K-means++).
(2) Assignment Step: Assign every point to its closest centroid by Euclidean distance.
(3) Update Step: Recompute each centroid as the mean of the points assigned to it.
(4) Convergence: Repeat assignment and update until the centroids stabilize or a stopping criterion is met.

Three well separated clusters colored by assignment with red X markers at the learned centroids

Figure 1: K-means (K=3) converged on blob data: colors mark the final assignments and the red X’s are the centroids: each is the mean of its cluster, and every point belongs to its nearest centroid’s cluster.

Mathematical Formulation:
d(x, c_k) = \sqrt{\sum_{i=1}^{n} (x_i - c_{k,i})^2}
c_k = \frac{1}{|C_k|} \sum_{x \in C_k} x

Where:

  • x is a data point and c_k the centroid of cluster k (first formula: Euclidean assignment distance, n = number of features).
  • C_k is the set of points currently assigned to cluster k; the update sets the centroid to their component-wise mean, the minimizer of squared distances for a fixed assignment.

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *