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

# S3 method for ALS
predict(model, data, key, used.cols = NULL, thread.ratio = NULL, ...)

Format

S3 methods

Arguments

model

R6Class object
An "ALS" object for prediction.

data

DataFrame
DataFrame containting the data.

key

character
Name of the ID column.

used.cols

list/vector of character, optional
Specifies the three columns of data that are used for model prediction.
Should arranged in the order of: user, item.
Otherwise, the list/vector must be named, shown as follows:

  • used.cols <- list(user = xxx, item = xxx)

Default to the first two non-ID columns if not provided..

thread.ratio

double, optional
Controls the proportion of available threads that can be used by this function.
The value range is from 0 to 1, where 0 indicates a single thread, and 1 indicates all available threads.
Values between 0 and 1 will use up to that percentage of available threads.Values outside this range are ignored.
Defaults to 0.

...

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.

  • user column, representing user names/IDs.

  • item column, represnetiing item names/IDs.

  • PREDICTION column, predicted feedback of user to item.

Examples

Perform the predict on DataFrame data2 using "ALS" object als:


> data2$Collect()
  ID USER     MOVIE
1  1    A    Movie3
2  2    A    Movie7
3  3    B    Movie1
4  4    B    Movie6
5  5    C    Movie3
6  6    D    Movie2
7  7    D    Movie5
8  8    E Bad_Movie

Call the function and obtain the result:


> pred.res <- predict(als, data = data2,
                      key = "ID",
                      used.cols = c(user = "USER"))
> pred.res$Collect()
  ID USER     MOVIE PREDICTION
1  1    A    Movie3   3.868747
2  2    A    Movie7   2.870243
3  3    B    Movie1   5.787559
4  4    B    Movie6   5.837218
5  5    C    Movie3   3.323575
6  6    D    Movie2   4.156372
7  7    D    Movie5   4.325851
8  8    E Bad_Movie   2.545807

See also