som {kohonen} | R Documentation |
Self-organising maps for mapping high-dimensional spectra or patterns
to 2D; the 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), init, toroidal = FALSE, FineTune = TRUE, 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 initial radius of the neighbourhood to be used for
each update: it decreases linearly to 1 over rlen
updates. The default is to start with a value that covers 2/3 of all
units. |
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. |
FineTune |
apply kmeans for fine-tuning the codebook vectors. |
keep.data |
save data in return value. |
an object of class "kohonen" with components
grid |
the grid, an object of class "somgrid". |
changes |
vector of mean average deviations from code vectors. |
codes |
a matrix of code vectors. |
classif |
winning units for all data objects. |
toroidal |
whether a toroidal map is used. |
data |
data matrix, only if keep.data is TRUE. |
Ron Wehrens
W.J. Melssen, R. Wehrens, and L.M.C. Buydens. Chemom. Intell. Lab. Syst., in press.
data(wines) set.seed(7) training <- sample(length(wine.classes), 120) Xtraining <- scale(wines[training,]) som.wines <- som(Xtraining, grid = somgrid(5, 5, "hexagonal"), rlen=100) Xtest <- scale(wines[-training,], center = attr(Xtraining, "scaled:center"), scale = attr(Xtraining, "scaled:scale")) som.classes <- rep(0, 25) for (i in 1:25) { mappedHere <- which(som.wines$classif == i) if (length(mappedHere) > 0) { classes.mappedHere <- wine.classes[training[mappedHere]] som.classes[i] <- names(table(classes.mappedHere))[table(classes.mappedHere) == max(table(classes.mappedHere))][1] } } som.prediction <- predict(som.wines, data=Xtest) somclass.prediction <- som.classes[som.prediction$unit.classif] table(wine.classes[-training], somclass.prediction)