| som {kohonen} | R Documentation |
Self-organising maps for mapping high-dimensional spectra or patterns
to 2D; Euclidean distance is used. Modelled after the SOM function in
package class.
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)
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 smaller than one only the winning unit will be updated. The default is to start with a value that covers 2/3 of all unit-to-unit distances. |
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. |
an object of class "kohonen" with components
data |
data matrix, only returned if keep.data == TRUE. |
grid |
the grid, an object of class "somgrid". |
codes |
a matrix of code vectors. |
changes |
vector of mean average deviations from code vectors. |
unit.classif |
winning units for all data objects,
only returned if keep.data == TRUE. |
distances |
distances of objects to their corresponding winning
unit, only returned if keep.data == TRUE. |
toroidal |
whether a toroidal map is used. |
method |
the type of som, here "som". |
Ron Wehrens
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 = classvec2classmat(wine.classes[training]))
table(wine.classes[-training],
classmat2classvec(som.prediction$prediction))