Description Usage Arguments Details Value Examples
View source: R/som.nn.validate.R
A model of type SOMnn
is tested with a validation dataset. The dataset must
include a column with correct class labels.
The model is used to predict class labels. Confusion table,
specificity, sensitivity and accuracy for each class are calculated.
1 | som.nn.validate(model, x)
|
model |
model of type |
x |
data.fame with validation data. Samples are requested as rows.
|
Parameters stored in the model are applied for k-NN-like prediction. If necessary
the parameters can be changed by som.nn.set
before testing.
The funcion is only a wrapper and actually calls som.nn.continue
with the test data and
without training (i.e. len = 0
).
S4 object of type SOMnn
with the unchanged model and the
test statistics for the test data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | ## get example data and add class labels:
data(iris)
species <- iris$Species
## train with default radius = diagonal / 2:
som <- som.nn.train(iris, class.col = "Species", kernel = "internal",
xdim = 15, ydim = 9, alpha = 0.2, len = 10000,
norm = TRUE, toroidal = FALSE)
## continue training with different alpha and radius;
som <- som.nn.continue(som, iris, alpha = 0.02, len=1000, radius = 5)
som <- som.nn.continue(som, iris, alpha = 0.02, len=1000, 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 = som@predict(setosa))
plot(som, predict = som@predict(versicolor), add = TRUE, pch.col = "magenta", pch = 17)
plot(som, predict = som@predict(virginica), add = TRUE, pch.col = "white", pch = 8)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.