som.nn.continue {som.nn} | R Documentation |
Continue hexagonal som training
Description
An existing self-organising map with hexagonal tolology is further trained and a model created for prediction of unknown samples. In contrast to a "normal" som, class-labels for all samples of the training set are required to build the model.
Usage
som.nn.continue(
model,
x,
kernel = "internal",
len = 0,
alpha = 0.2,
radius = 0
)
Arguments
model |
model of type |
x |
data.fame with training data. Samples are requested as rows and taken randomly for the
training steps. All
columns except of the class lables are considered to be attributes and parts of
the training vector.
|
kernel |
Kernel for som training. One of the predefined kernels
|
len |
number of steps to be trained (steps - not epochs!). |
alpha |
initial training rate; default 0.02. |
radius |
inital radius for SOM training. If Gaussian distance function is used, radius corresponds to sigma. |
Details
Any specified custom kernel function is used for som training. The function must match the
signature kernel(data, grid, rlen, alpha, radius, init, toroidal)
, with
arguments:
-
data
numeric
matrix of training data; one sample per row -
classes:
optionalcharater
vector of classes for training data -
grid
somgrid, generated withsomgrid
-
rlen
number of training steps -
alpha
training rate -
radius
training radius -
init
numeric
matrix of initial codebook vectors; one code per row -
toroidal
logical
; TRUE, if the topology of grid is toroidal
The returned value must be a list with at minimum one element
-
codes:
numeric
matrix of result codebook vectors; one code per row
Value
S4 object of type \code{\link{SOMnn}} with the trained model
Examples
## get example data and add class labels:
data(iris)
species <- iris$Species
## train with default radius = diagonal / 2:
rlen <- 500
som <- som.nn.train(iris, class.col = "Species", kernel = "internal",
xdim = 15, ydim = 9, alpha = 0.2, len = rlen,
norm = TRUE, toroidal = FALSE)
## continue training with different alpha and radius;
som <- som.nn.continue(som, iris, alpha = 0.02, len=500, radius = 5)
som <- som.nn.continue(som, iris, alpha = 0.02, len=500, radius = 2)
## predict some samples:
unk <- iris[,!(names(iris) %in% "Species")]
setosa <- unk[species=="setosa",]
setosa <- setosa[sample(nrow(setosa), 20),]
versicolor <- unk[species=="versicolor",]
versicolor <- versicolor[sample(nrow(versicolor), 20),]
virginica <- unk[species=="virginica",]
virginica <- virginica[sample(nrow(virginica), 20),]
p <- predict(som, unk)
head(p)
## plot:
plot(som)
dev.off()
plot(som, predict = predict(som, setosa))
plot(som, predict = predict(som, versicolor), add = TRUE, pch.col = "magenta", pch = 17)
plot(som, predict = predict(som, virginica), add = TRUE, pch.col = "white", pch = 8)