[R] Self-Organizing Map analysis

Hans W. Borchers hwborchers at gmail.com
Wed Mar 4 09:13:09 CET 2009


glaporta <glaporta <at> freeweb.org> writes:

> 
> Dear list,
> I read the SOM package manual but I don't understand how to perform (for
> example) 1) the SOM analysis on Iris data 2) with a visualization similar to
> that of figure 7 in
> http://www.cis.hut.fi/projects/somtoolbox/package/papers/techrep.pdf


In R, I used the following calls to create SOM maps similar to the ones in the
literature (I don't find the SOM toolbox figures particularly inspiring):

----
  library("class")
  data(iris)

  n <- 10
  sg <- somgrid(n, n, "rectangular")
  df.som <- batchSOM(df, sg, c(4,4,3,3,2,2,1,1))

  windows(record=TRUE)
  for (i in 1:ncol(df)) {
    xy <- matrix(df.som$codes[,i], n, n)
    image(xy)
    contour(xy, add=T)
    grid(col="gray")
  }
----

Of course, there are not enough Iris data to generate a reasonable SOM grid. At
least  n <- 30  is needed for a nice graph, and that means at least 1000 data
points.

Using a Binhex grid instead of a rectangular one will result in diagrams similar
to those from the SOM toolbox. But then the 'image' call has to be a bit
prepared for this.

Regards,  Hans Werner


> Any suggestion? Thanks in advance,
> Gianandrea




More information about the R-help mailing list