predict.hdgsom: Predict function for hdgsom

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

View source: R/predict.hdgsom.r

Description

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

Usage

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

Arguments

object

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

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 hdgsom object.

...

not used.

Value

hdgsom object containing the following information:

nodes$position

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

nodes$codes

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

nodes$predict

a matrix containing the codes for each property that are to be modelled (copied from the input hdgsom 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.hdgsom, map.hdgsom

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 hdgsom Model (hexagonal grid)
  hdgsom_map <- train_xy.hdgsom(train_set[,2:8], train_set[,1], spreadFactor = 0.9, nhood="hex")
  
  print(hdgsom_map)
  plot(hdgsom_map, type = "predict")
  
  # Predict mpg for the test set
  hdgsom_predictions = predict.hdgsom(hdgsom_map, test_set[,2:8])

alecuba16/HDGSOM documentation built on April 11, 2020, 5:06 a.m.