predict.KMeans.Rd
Similar to other predict methods, this function predicts fitted values from a fitted "KMeans" object.
# S3 method for KMeans
predict(model, data, key, features = NULL, ...)
S3
methods
R6Class object
A 'KMeans' object for prediction.
DataFrame
DataFrame containting the data.
character
Name of the ID column.
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.
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