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 30.3.4), 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!

Image rplot-cluster

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-2010 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
The PDF version is a formatted comprehensive draft book (with over 800 pages).
Brought to you by Togaware. This page generated: Sunday, 22 August 2010