Working mechanics of the k-means algorithm

The execution of the k-means algorithm involves the following steps:

  1. Randomly select k observations from the dataset as the initial cluster centroids.
  2. For each observation in the dataset, perform the following:
    1. Compute the distance between the observation and each of the cluster centroids.
    2. Identify the cluster centroid that has minimum distance with the observation.
    3. Assign the observation to such closest centroid.
  1. With all points assigned to one of the cluster centroids, compute new cluster centroids. This can be done by taking the mean of all the points assigned to a cluster.
  2. Perform step 2 and step 3 repeatedly until the cluster centroids (mean) do not change or until a user-defined number ...

Get R Machine Learning Projects now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.