The k-means clustering aims to partition observations into clusters in which each observation belongs to the cluster with the nearest mean, serving as a prototype (clustering center) of the cluster. Generally speaking, it may include a series of iterations: finding cluster centers, computing distances between sample points, and redefining cluster membership. It is one of the top 10 algorithms in data mining.

In the animation package, function kmeans.ani() is a demonstration for k-means cluster algorithm, here is the example. The beautiful graph let me think this demostration function is the best one in the animation package.

library(animation)
cent = 1.5 * c(1, 1, -1, -1, 1, -1, 1, -1)
x = NULL
for (i in 1:8) x = c(x, rnorm(25, mean = cent[i]))
x = matrix(x, ncol = 2)
kmeans.ani(x, centers = 4, pch = 1:4, col = 1:4)


Published

08 May 2013

Tags