After training a SOM, how can you plot new data onto the SOM and visualise how it maps onto the SOM? Ideally, I would like for it to be plotted with the corresponding classification colour and node location. identify()
has the capability of pinpointing data based on selections on the SOM map but it is very limited and can only do one at a time. I would like to map a whole (new) dataset and visualise it. I am able to get the node location from using map()
and the group association, but how can I manually plot the new points onto the SOM? Couldn't find anything pertinent on the internet or the kohonen R documentation. Appreciate any help.
library(kohonen)
data(wines)
wines.train<-wines[1:150,]
wines.test<-wines[151:nrow(wines),]
wines.sc <- scale(wines.train)
set.seed(7)
wines.som<-som(wines.sc, grid = somgrid(5, 4, "hexagonal"),rlen=150,alpha=c(0.05,0.01))
wines.hc<-cutree(hclust(dist(wines.som$codes[[1]])),6)
plot(wines.som,type="mapping",bgcol=rainbow(6)[wines.hc])
add.cluster.boundaries(wines.som,wines.hc)
can be used to manually inspect specific nodes on SOM
identify(wines.som$grid$pts,labels=as.vector(wines.hc),plot=T,pos=T)
map new data onto trained SOM
wines.map<-map(wines.som,scale(wines.test))
wines.test.grp<-sapply(wines.map$unit.classif,function(x) wines.hc[[x]])