Lably
Skip to content

K-means clustering

Vector quantization algorithm minimizing the sum of squared deviations

  • 27 min read
  • 8 chapters
  • 4 labs on Lably

Learn it on Lably

The problem is computationally difficult (NP-hard); however, efficient heuristic algorithms converge quickly to a local optimum. These are usually similar to the expectation–maximization algorithm for mixtures of Gaussian distributions via an iterative refinement approach employed by both k-means and Gaussian mixture modeling. They both use cluster centers to model the data; however, k-means clustering tends to find clusters of comparable spatial extent, while the Gaussian mixture model allows clusters to have different shapes.

The unsupervised k-means algorithm has a loose relationship to the k-nearest neighbor classifier, a popular supervised machine learning technique for classification that is often confused with k-means due to the name. Applying the 1-nearest neighbor classifier to the cluster centers obtained by k-means classifies new data into the existing clusters. This is known as nearest centroid classifier or Rocchio algorithm.

Description

Given a set of observations (x1, x2, ..., xn), where each observation is a d-dimensional real vector, k-means clustering aims to partition the n observations into k (≤ n) sets S = {S1, S2, ..., Sk} so as to minimize the within-cluster sum of squares (WCSS) (i.e. variance). Formally, the objective is to find: argminS⁡∑i=1k∑x∈Si‖x−μi‖2=argminS⁡∑i=1k|Si|Var⁡Si where μi is the mean (also called centroid) of points in Si, i.e. μi=1|Si|∑x∈Six, |Si| is the size of Si, and ‖⋅‖ is the usual L2 norm . This is equivalent to minimizing the pairwise squared deviations of points in the same cluster: argminS⁡∑i=1k1|Si|∑x,y∈Si‖x−y‖2 The equivalence can be deduced from the identity |Si|∑x∈Si‖x−μi‖2=12∑x,y∈Si‖x−y‖2. Since the total variance is constant, this is equivalent to maximizing the sum of squared deviations between points in different clusters (between-cluster sum of squares, BCSS). This deterministic relationship is also related to the law of total variance in probability theory.

Sign in to keep reading

7 more chapters are free with a Lably account.

More in Computing and communication