recosystem (version 0.4.4)

predict: Recommender Model Predictions

Description

This method is a member function of class "RecoSys" that predicts unknown entries in the rating matrix.

Prior to calling this method, model needs to be trained using member function $train().

The common usage of this method is

r = Reco()
r$train(...)
r$predict(test_data, out_pred = data_file("predict.txt")

Arguments

r

Object returned by Reco().

train_data

An object of class "DataSource" that describes the source of testing data, typically returned by function data_file() or data_memory().

out_pred

An object of class Output that specifies the output format of prediction, typically returned by function out_file(), out_memory() or out_nothing(). out_file() writes the result into a file, out_memory() exports the vector of predicted values into the return value of $predict(), and out_nothing() means the result will be neither returned nor written into a file (but computation will still be conducted).

References

W.-S. Chin, Y. Zhuang, Y.-C. Juan, and C.-J. Lin. A Fast Parallel Stochastic Gradient Method for Matrix Factorization in Shared Memory Systems. ACM TIST, 2015.

W.-S. Chin, Y. Zhuang, Y.-C. Juan, and C.-J. Lin. A Learning-rate Schedule for Stochastic Gradient Methods to Matrix Factorization. PAKDD, 2015.

W.-S. Chin, B.-W. Yuan, M.-Y. Yang, Y. Zhuang, Y.-C. Juan, and C.-J. Lin. LIBMF: A Library for Parallel Matrix Factorization in Shared-memory Systems. Technical report, 2015.

See Also

$train()

Examples

Run this code
# NOT RUN {
train_file = data_file(system.file("dat", "smalltrain.txt", package = "recosystem"))
test_file = data_file(system.file("dat", "smalltest.txt", package = "recosystem"))
r = Reco()
set.seed(123) # This is a randomized algorithm
opts_tune = r$tune(train_file)$min
r$train(train_file, opts = opts_tune)

## Write predicted values into file
out_pred = out_file(tempfile())
r$predict(test_file, out_pred)

## Return predicted values in memory
pred = r$predict(test_file, out_memory())

## If testing data are stored in memory
test_df = read.table(test_file@source, sep = " ", header = FALSE)
pred2 = r$predict(data_memory(test_df[, 1], test_df[, 2]), out_memory())

## Compare results
print(scan(out_pred@dest, n = 10))
head(pred, 10)
head(pred2, 10)
# }
# NOT RUN {
# }

Run the code above in your browser using DataCamp Workspace