Desktop Survival Guide
by Graham Williams

Basic Clustering

We illustrate very simple clustering through a complete example where the task is to read data from a file (See Section [*]), extract the numeric fields, and then use k-means (See Chapter [*]) to cluster on just two columns. A plot of the clusters over the two columns shows the points and the cluster centroids. Normally, the clusters would be built over more than just two columns. Also note that each time the code is run a different clustering is likely to be generated!

clusters <- 5
pdf("graphics/rplot-cluster.pdf") = kmeans(wine[,2:3], clusters)
  points($centers, pch=19, cex=1.5, col=1:clusters)

The resulting cluster entity has the following entries:
cluster: The cluster that each row belongs to.
centers: The medoid of each cluster.
withinss: The within cluster sum of squares.
size: The size of each cluster.

Copyright © 2004-2006 [email protected]
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware.