Learn R Programming

kohonen (version 2.0.5)

som: Kohonen's self-organising maps

Description

Self-organising maps for mapping high-dimensional spectra or patterns to 2D; Euclidean distance is used. Modelled after the SOM function in package class.

Usage

som(data, grid=somgrid(), rlen = 100, alpha = c(0.05, 0.01),
    radius = quantile(nhbrdist, 0.67) * c(1, -1), init,
    toroidal = FALSE, n.hood, keep.data = TRUE)

Arguments

data
a matrix, with each row representing an object.
grid
a grid for the representatives: see 'somgrid'.
rlen
the number of times the complete data set will be presented to the network.
alpha
learning rate, a vector of two numbers indicating the amount of change. Default is to decline linearly from 0.05 to 0.01 over rlen updates.
radius
the radius of the neighbourhood, either given as a single number or a vector (start, stop). If it is given as a single number the radius will run from the given number to the negative value of that number; as soon as the neighbourhood gets sma
init
the initial representatives, represented as a matrix. If missing, chosen (without replacement) randomly from 'data'.
toroidal
if TRUE, the edges of the map are joined. Note that in a hexagonal toroidal map, the number of rows must be even.
n.hood
the shape of the neighbourhood, either "circular" or "square". The latter is the default for rectangular maps, the former for hexagonal maps.
keep.data
save data in return object.

Value

  • an object of class "kohonen" with components
  • datadata matrix, only returned if keep.data == TRUE.
  • gridthe grid, an object of class "somgrid".
  • codesa matrix of code vectors.
  • changesvector of mean average deviations from code vectors.
  • unit.classifwinning units for all data objects, only returned if keep.data == TRUE.
  • distancesdistances of objects to their corresponding winning unit, only returned if keep.data == TRUE.
  • toroidalwhether a toroidal map is used.
  • methodthe type of som, here "som".

See Also

xyf, bdk, plot.kohonen

Examples

Run this code
data(wines)
set.seed(7)

training <- sample(nrow(wines), 120)
Xtraining <- scale(wines[training, ])
Xtest <- scale(wines[-training, ],
               center = attr(Xtraining, "scaled:center"),
               scale = attr(Xtraining, "scaled:scale"))

som.wines <- som(Xtraining, grid = somgrid(5, 5, "hexagonal"))

som.prediction <- predict(som.wines, newdata = Xtest,
          trainX = Xtraining,
          trainY = factor(wine.classes[training]))
table(wine.classes[-training], som.prediction$prediction)

Run the code above in your browser using DataLab