Jump to content

Machine learning/Unsupervised Learning/K-means Clustering

K-means is a method of clustering which is an unsupervised learning problem.

  • In this method the number of clusters is an input to the algorithm (hyper-parameter).
  • K-means method is a greedy algorithm. It is a special case of expectation maximization (EM) algorithm, in which we try to find maximum likelihood expectation (MLE).
  • K-means algorithm is not guaranteed to converge to the global mean of the loss function (sum of Euclidean distances from each cluster center). The global minimum problem is an NP hard problem.

Relation to Gaussian Mixture Model (GMM):

[edit | edit source]
  • GMM is a more probabilistic approach to clustering.
  • Expectation maximization (EM) algorithm is used to find a good gaussian mixture model to cluster the data.

Intuition

[edit | edit source]

Data points in each cluster are closer to the center of each cluster than the center of other clusters.

Algorithm

[edit | edit source]

Assume that the number of clusters is given by k and the cluster centers are shown with μ1,μ2,⋯,μk∈ℝd.

We define a loss function for clustering and try to minimize it through the following greedy algorithm.

The loss function is defined as

L=∑j=1k∑iaij||xi−μj||2whereaij={1if xi assigned to j0else

Minimize L with respect to a and μ by following these two steps until convergence is achieved:

  1. Choose optimal a for fixed μ by assigning xi to the nearest μjaij={1if j=arg⁡minl|xi−μl|20else
  2. Choose optimal μ for fixed a by updating μj to be the empirical mean of the points assigned to each clusterμj=1nj∑i:xi in jxi where nj=∑i=1maij=number of data points assigned to j

Justification

[edit | edit source]

In this section, we show that choosing cluster center, μj, according to step 2 of the algorithm minimized loss function for a fixed set of assignment factors (aij)

In order to find the minimum value of loss function (L) as a function of μj, we find the point for which the gradient of the function is zero

∇μjL=0Therefore, we have

∇μjL=∑iaij∇μj(xi−μj)T(xi−μj)=∑iaij∇μj(xiTxi−2μjTxi+μjTμj)=∑iaij(−2xi+2μj)=0Getting rid of the factor of 2 in the last expression we have μj∑iaij=∑iaijxi⇒μj=∑iaijxi∑iaijWe also have nj=∑i=1naij=#{i:xi is assigned to j}, which simplifies μj toμj=1nj∑i:xi in jxi