Self-organizing map (SOM) example in R
#SOM example using wines data set | |
library(kohonen) | |
data(wines) | |
set.seed(7) | |
#create SOM grid | |
sommap <- som(scale(wines), grid = somgrid(2, 2, "hexagonal")) | |
## use hierarchical clustering to cluster the codebook vectors | |
groups<-3 | |
som.hc <- cutree(hclust(dist(sommap$codes)), groups) | |
#plot | |
plot(sommap, type="codes", bgcol=rainbow(groups)[som.hc]) | |
#cluster boundaries | |
add.cluster.boundaries(sommap, som.hc) |
This comment has been minimized.
This comment has been minimized.
Getting Error in dist(sommap$codes) : Any one to assist. Am a newbie in R |
This comment has been minimized.
This comment has been minimized.
I tried this and then no more error but not sure if this is the correct way. I am a newbie too |
This comment has been minimized.
This comment has been minimized.
following works
|
This comment has been minimized.
This comment has been minimized.
i am a little confused about how to do clustering using the result of SOM... |
This comment has been minimized.
This comment has been minimized.
How can you define the number of groups to be 3? |
This comment has been minimized.
This comment has been minimized.
som.hc <- cutree(hclust(dist(sommap$codes[[1]])), groups) |
This comment has been minimized.
This comment has been minimized.
I follow yours suggested and it works |
This comment has been minimized.
This comment has been minimized.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Getting:
Error in dist(sommap$codes) :
(list) object cannot be coerced to type 'double'
any ideas?