This is my personal notes taken for the course Machine learning by Standford. Feel free to check the assignments.
Also, if you want to read my other notes, feel free to check them at my blog.
In the clustering problem, we are given a training set ,and want to group the data into a few cohesive "clusters". Here, as usual; but no labels are given. So, this is an unsupervised learning problem. The k-means clustering algorithm is as follows:
In the algorithm above, we have:
To initialize the cluster centroids (in step 1 of the algorithm above), we could choose training examples randomly, and set the cluster centroids to be equal to the values of these examples. (Other initialization methods are also possible).
The inner-loop is then compose of 2 steps:
We assign each training example to the nearest cluster centroid . To do so, we need to find the value that minimizes (Euclidean distance).
Compute the averages for all the points inside each of the cluster centroid groups , then move the cluster centroid points to those averages.
Remark:
Thus,
Is the k-means algorithm guaranteed to converge? Yes it is, in a certain sense. In particular, let us define the distortion function to be:
where is cluster centroid of the cluster to which example has been assigned.
It can be shown that k-means is exactly coordinate descent on .
The distortion function is a non-convex function, and so coordinate descent on is not guaranteed to converge to the global minimum. In other words, k-means can be susceptible to local optima. Very often k-means will work fine and come up with very good clusterings despite this. But if you are worried about getting stuck in bad local minima, one common thing to do is run k-means many times (using different random initial values for the cluster centroids ). Then, out of all the different clusterings found, pick the one that gives the lowest distortion .
What is coordinate descent ?
Coordinate descent is an optimization algorithm that find the minimum of a function by minimizing one parameters at the time while holding others fixed.
In the case of distortion function, , we will do the following:
Thus, must monotonically decrease, and the value of must converge. (Usually, this implies that and will converge too).