Last active
March 11, 2023 11:21
-
-
Save dgrapov/f67d0696c4fb02731f55da3e1b9e8c4d to your computer and use it in GitHub Desktop.
Self-organizing map (SOM) example in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
related blog post: https://imdevsoftware.wordpress.com/2016/05/19/push-it-to-the-limit-som-clustering-networks/