kmeans.ani(x = matrix(runif(100), ncol = 2), centers = 2,
control = ani.control(interval = 2, nmax = 30), ...)
x
is chosen as the initial centers.ani.control
ani.control
x
is clustered by the k-means method, which aims to partition the points into k groups such that the sum of squares from points to the assigned cluster centers is minimized. At the minimum, all cluster centres are at the mean of their Voronoi sets (the set of data points which are nearest to the cluster centre).
For practical applications please refer to kmeans
.
Note that nmax
is defined as the maximum number of iterations in such a sense: an iteration includes the process of computing distances, redefining membership and finding centers. Thus there might be 2*nmax
animation frames in the output if saveANI = TRUE
.kmeans
#set larger 'interval' if the speed is too fast
x = matrix(runif(200), ncol = 2)
kmeans.ani(x = x, centers = 2, interval = 0.5)
# create HTML animation page
op = par(mar = c(2, 2, 3, 1), cex.axis = 0.75, cex.main = 1)
ani.start()
kmeans.ani(saveANI = TRUE, x = x, centers = 3, interval = 1,
width = 600, height = 600)
ani.stop()
par(op)
Run the code above in your browser using DataLab