predict.gsom: Predict function for gsom

Description Usage Arguments Value Note Author(s) See Also Examples

View source: R/predict.gsom.r

Description

Map objects to a supervised GrowingSOM map, and return for each object the property associated with the corresponding winning node.

Usage

1
2
## S3 method for class 'gsom'
predict(object, df, retaindata = FALSE, ...)

Arguments

object

a trained supervised gsom object. (see train_xy.gsom)

df

Matrix or Dataframe of observations for which the Y values should be predicted.
Columns of this input argument must be corresponding to the ones used as data when training the map.

retaindata

logical. If set to TRUE a copy of the mapped data (df) is stored as a copy in the returned gsom object.

...

not used.

Value

gsom object containing the following information:

nodes$position

Coordinates of the units of the map (copied from the input gsom map)

nodes$codes

a matrix containing the codes for each variable of each node (copied from the input gsom map)

nodes$predict

a matrix containing the codes for each property that are to be modelled (copied from the input gsom map)

nodes$freq

the number of observations that were mapped to each node.

prediction$bmn

best matching node for each observation provided.

prediction$dist

distance measurement of observations to their best matching units.

prediction$value

prediction for the modelled properties for each observation.

Note

Distance Measurement: The following Formula is used for determining the distance from the best matching unit:
sqrt((sum(df-code))^2 / Dimenstions)
This is a different scale than is used by the kohonen package.

Author(s)

Alex Hunziker

See Also

train_xy.gsom, map.gsom

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
  # load data
  data("auto_mpg")
  s = sample(1:392, 300)
  train_set = auto_mpg[s,1:8]
  test_set = auto_mpg[-s,1:8]
  
  # Train Gsom Model (hexagonal grid)
  gsom_map <- train_xy.gsom(train_set[,2:8], train_set[,1], spreadFactor = 0.9, nhood="hex")
  
  print(gsom_map)
  plot(gsom_map, type = "predict")
  
  # Predict mpg for the test set
  gsom_predictions = predict.gsom(gsom_map, test_set[,2:8])

GrowingSOM documentation built on May 30, 2017, 6:24 a.m.