How can I find out which data record goes into which cluster in R using kohonen and means

327 views Asked by At

I have clustered my data with an SOM and kmeans

install.packages("kohonen")
library(kohonen)
set.seed(7)

som_grid <- somgrid(xdim = 8, ydim=8, topo="hexagonal")

som_model <- som(umfrage_veraendert_kurz, 
             grid=som_grid, 
             rlen=500, 
             alpha=c(0.05,0.01), 
             keep.data = TRUE )

I get from my som_model the "codes" and clustered it with kmeans

mydata <- som_model$codes

clusterzentren <- kmeans(mydata, center=3)
head(clusterzentren)

I have now 3 clusters but I don't know which data record goes to which cluster? How can I find it out?

Thanks for any help

1

There are 1 answers

1
Has QUIT--Anony-Mousse On

The return value of kmeans is a S3 object which contains not only the centers, but also the cluster assignment.

See the R manual of kmeans for details.