I have a recommendation problem that is fairly simple: I would like build a hybrid recommender with recommenderlab
in R where I recommend already liked movies in the MovieLense
data set together with popular movies and some random movies.
library(recommenderlab)
data("MovieLense")
MovieLense100 <- MovieLense[rowCounts(MovieLense) > 100,]
train <- MovieLense100[1:100]
test <- MovieLense100[101:103]
## mix popular movies with a random recommendations for diversity and
## rerecommend some movies the user liked.
recom <- HybridRecommender(
Recommender(train, method = "POPULAR"),
Recommender(train, method = "RANDOM"),
Recommender(train, method = "RERECOMMEND"),
weights = c(.6, .1, .3)
)
When I have trained the model I would like to "predict" the movies for a given user using the userId. The Recommenderlab documentation suggests that this is possible as long as the userid is in the training data. However, when I try predicting using a userid
in newdata
I get the following error message:
as(predict(object = recom, newdata = 1), "list")
#> Error in object@predict(object@model, newdata, n = n, data = data, type = type, : If newdata is a user id then data needes to be the training dataset.
Fair enough, I try with a vector:
as(predict(recom, newdata = c(1,5)), "list")
#> Error in object@predict(object@model, newdata, n = n, data = data, type = type, : If newdata is a user id then data needes to be the training dataset.
Can't really figure out what this error message mean. Does anybody know?
You just need to precise that you are recommending items to the user or users from the training dataset as followed :
Otherwise, the predict function we not know what user are you referring to.
You can also predict on test data as followed :