| somInit | R Documentation | 
Prototypes are the artificial points in data space that are used to cluster
observations: each observation is assigned to the cluster of its closest
prototype. In self-organizing maps, each cell of the map has its own
prototype, and training is performed by iteratively adjusting the prototypes.
This function creates an initial guess for the prototypes of a SOM grid, to
be used as the init argument to the kohonen::som function (see example).
somInit(traindat, nrows, ncols, method = c("pca.sample", "pca", "random"))
| traindat | Matrix of training data, that will also be used to train the SOM. | 
| nrows | Number of rows on the map. | 
| ncols | Number of columns on the map. | 
| method | Method used, see Details. "pca" or "random" | 
The default method "pca.sample" takes as prototypes the observations that are closest to the nodes of a 2d grid placed along the first two components of a PCA. The "pca" method uses the nodes instead of the observations. The "random" method samples random observations.
A matrix of prototype coordinates.
dat <- iris[, c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")]
### Scale training data
dat <- scale(dat)
## Train SOM
### Initialization (PCA grid)
init <- somInit(dat, 4, 4)
the.som <- kohonen::som(dat, grid = kohonen::somgrid(4, 4, 'hexagonal'), 
                        rlen = 100, alpha = c(0.05, 0.01), 
                        radius = c(2.65,-2.65), init = init, 
                        dist.fcts = 'sumofsquares')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.