Learn R Programming

GrowingSOM (version 0.1.1)

predict.gsom: Predict function for gsom

Description

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

Usage

"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:

See Also

train_xy.gsom, map.gsom

Examples

Run this code
  # 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])

Run the code above in your browser using DataLab