predict.KMeans.RdSimilar to other predict methods, this function predicts fitted values from a fitted "KMeans" object.
# S3 method for KMeans predict(model, data, key, features = NULL, ...)
| model |
|
|---|---|
| data |
|
| key |
|
| features |
|
| ... | Reserved parameter. |
S3 methods
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 cluster center.
Perform the predict on DataFrame data2 using "KMeans" object km:
> data2$Collect() ID V000 V001 V002 1 0 0.5 A 0.5 2 1 1.5 A 0.5 3 2 1.5 A 1.5 4 3 0.5 A 1.5 5 4 1.1 B 1.2 ...... 19 18 15.5 D 1.5 20 19 15.7 A 1.6 > fitted <- predict(model = km, data = data2, key = "ID")
Output:
> fitted$Collect()
ID CLUSTER_ID DISTANCE
1 0 0 0.9496364
2 1 0 0.9224655
3 2 0 0.8648006
4 3 0 0.8942320
5 4 0 0.9787646
......
19 18 3 0.7813475
20 19 3 1.3365355