if (FALSE) {
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, out_model = NULL, 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)
test_data = data_memory(test_df[, 1], test_df[, 2])
pred2 = r$predict(test_data, out_memory())
## Compare results
print(scan(out_pred@dest, n = 10))
head(pred, 10)
head(pred2, 10)
## If testing data are stored as a sparse matrix
if(require(Matrix))
{
mat = Matrix::sparseMatrix(i = test_df[, 1], j = test_df[, 2], x = -1,
repr = "T", index1 = FALSE)
test_data = data_matrix(mat)
pred3 = r$predict(test_data, out_memory())
print(head(pred3, 10))
}
}
Run the code above in your browser using DataLab