Similar to other predict methods, this function predicts fitted values from a fitted "SOM" object.

# S3 method for SOM
predict(model, data, key, features = NULL, ...)

Format

S3 methods

Arguments

model

R6Class object
A 'SOM' object for prediction.

data

DataFrame
DataFrame containting the data.

key

character
Name of the ID column.

features

character of list of characters, optional
Name of feature columns for prediction.
If not provided, it defaults to all non-key columns of data.

...

Reserved parameter.

Value

Predicted values are returned as a DataFrame, structured as follows.

  • ID column, with same name and type as data 's ID column.

  • Cluster_ID, type INTEGER, the assigned cluster ID.

  • DISTANCE, type DOUBLE, Distance between a given point and the weight vector.

Examples

Perform the predict on DataFrame data2 using "SOM" object som:


> data2$Collect()
   TRANS_ID  V000  V001
1         0  0.10  0.20
2         1  0.22  0.25
3         2  0.30  0.40
4         3  0.40  0.50
5         4  0.50  1.00
......
18       17 50.20 48.30
19       18 55.30 50.40
20       19 50.40 56.50

> fitted <- predict(model = som, data = data2)

Output:


> fitted$Collect()
   TRANS_ID CLUSTER_ID     DISTANCE
1         0         15 3.425638e-01
2         1         15 2.396760e-01
3         2         15 7.396834e-02
4         3         15 9.763190e-02
5         4         15 5.609020e-01
......
18       17          1 9.465344e-01
19       18          0 3.931820e+00
20       19          0 3.892501e+00

See also