predict.kernelsom: Map new data to a fitted Kernel Self-Organising Map

Description Usage Arguments Details Value Author(s) Examples

Description

Map new data to a fitted Self-Organising Map, i.e., compute the best matching unit for each given observation.

Usage

1
2
3
## S3 method for class 'kernelsom'
predict(object, newdata, newdatanorms,
        with.secondwinner=FALSE,...)

Arguments

object

an object of class "kernelsom"

newdata

a matrix compatible with the fitted som (see details)

newdatanorms

a vector containing the squared norm in kernel space of the new data (see details)

with.secondwinner

switch to specify whether the second best matching unit should be computed and returned

...

not used

Details

The newdata matrix must contain the values of the kernel used to fit the SOM evaluated between the original data and the new data. More precisely, newdata[i,j] contains the value of K(x_i,nx_j), where x_i is the i-th original data point and nx_j is the j-th new data point.

While this is not needed to compute the best matching unit, this function requires in addition the value of the squared norm in kernel space of the new data, that is a vector newdatanorms such that newdatanorms[j] contains K(nx_j,nx_j).

Value

A list with components

classif

a vector of integer indicating to which unit each observation has been assigned

error

the quantisation error of the observations by the prototypes of this Self-Organising Map (see error.quantisation.kernelsom for a definition of this value)

rdist

a matrix of squared dissimilarities between the new data and the prototypes (some values might be negative if the underlying kernel is not positive)

winners

if with.secondwinner=TRUE a two column matrix with a line per observation containing the index of the best matching unit and of the second best matching unit (in this order)

Author(s)

Fabrice Rossi

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
data(iris)
# scaling
data <- scale(iris[1:4])

# use only part of the data
train <- sample(1:nrow(data),100)
data.train <- data[train,]
K <- as.kernelmatrix(tcrossprod(data.train))

# a small hexagonal grid
sg <- somgrid(xdim=5,ydim=5,topo="hex")

# fit the SOM
som <- batchsom(K,sg)

# map remaining data
results <- predict(som,tcrossprod(data.train,data[-train,]),
                   diag(tcrossprod(data[-train,])))
print(paste("Learning quantisation error:",error.quantisation(som)))
print(paste("Test quantisation error:",results$error))

yasomi documentation built on May 2, 2019, 5:59 p.m.