GNU/Linux Desktop Survival Guide by Graham Williams |
|||||
The task is to read some data, extract some numeric fields, convert to a matrix for efficiency (rather than data frame), and cluster.
df <- read.csv("wine.csv") # Read in some data. ds <- as.matrix(df[,1:10]) # Extract numeric into matrix. cl <- kmeans(ds, 10) # Generate 10 clusters. plot(ds, col=cl$cluster) # Show the clusters. plot(ds[,c(12,13)], col=cl$cluster) # Show just two variable plot. |
The resulting cluster will have the following fields:
$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. |