Skip to content

Instantly share code, notes, and snippets.

@mikelove
Created December 3, 2014 19:55
Show Gist options
  • Save mikelove/ee98799eaa0e6b15e55d to your computer and use it in GitHub Desktop.
Save mikelove/ee98799eaa0e6b15e55d to your computer and use it in GitHub Desktop.
som
n <- 20^2
p <- 4
col <- rep(1:2,each=n/2)
x <- matrix(rnorm(n*p),ncol=p)
x[,1] <- c(rnorm(n/2,0,1),rnorm(n/2,4,.1))
x[,2] <- c(rnorm(n/2,0,1),rnorm(n/2,4,.1))
par(mfrow=c(2,2))
plot(x[,1:2],col=col)
plot(prcomp(x)$x[,1:2],col=col,asp=1)
library(kohonen)
s <- som(data = x, grid = somgrid(sqrt(n), sqrt(n), "hexagonal"))
plot(s,type="counts")
plot(s,type="codes")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment