# NOT RUN {
ratings <- list(list(0, 0, 4.0), list(0, 1, 2.0), list(1, 1, 3.0), list(1, 2, 4.0),
list(2, 1, 1.0), list(2, 2, 5.0))
df <- createDataFrame(ratings, c("user", "item", "rating"))
model <- spark.als(df, "rating", "user", "item")
# extract latent factors
stats <- summary(model)
userFactors <- stats$userFactors
itemFactors <- stats$itemFactors
# make predictions
predicted <- predict(model, df)
showDF(predicted)
# save and load the model
path <- "path/to/model"
write.ml(model, path)
savedModel <- read.ml(path)
summary(savedModel)
# set other arguments
modelS <- spark.als(df, "rating", "user", "item", rank = 20,
regParam = 0.1, nonnegative = TRUE)
statsS <- summary(modelS)
# }
Run the code above in your browser using DataLab