predict.KNNRegressor.RdMake Predictions from a "KNNRegressor" Object
# S3 method for KNNRegressor predict( model, data, key, features = NULL, stat.info = NULL, thread.ratio = NULL )
| model |
|
|---|---|
| data |
|
| key |
|
| features |
|
| stat.info |
|
| thread.ratio |
|
S3 methods
Returns a list of DataFrame.
DataFrame 1: Prediction results, structured as follows.
ID column, with same name and type as data's ID column.
TARGET column, type NVARCHAR, predicted class labels or values.
DataFrame 2: Statistics of the prediction results.
The distance between each point in `data` and its k nearest
neighbors in the training set. Only returned if stat.info is TRUE.
TEST_ + data's ID name, with same type as data's ID column, query data ID.
K, type INTEGER, K number.
TRAIN_ + training data's ID name, with same type as training data's ID column, neighbor point's ID.
DISTANCE, type DOUBLE, distance.
DataFrame df.pred for prediction:
> df.pred ID X1 X2 X3 1 0 2 1 A 2 1 1 10 C 3 2 1 11 B 4 3 3 15000 C 5 4 2 1000 C 6 5 1 1001 A 7 6 1 999 A 8 7 3 999 B
Call the function using a "KNNRegressor" Object knr:
> res <- predict(model = knr,
data = df.pred,
key = "ID",
features = c("X1", "X2", "X3"),
stat.info = FALSE)
Output:
> res$Collect() ID TARGET 1 0 7.00000 2 1 7.00000 3 2 7.00000 4 3 36.66667 5 4 36.66667 6 5 36.66667 7 6 39.66667 8 7 69.33333