我是推荐实验室套餐和S4课程的新手,所以请耐心等待。 目的是根据参与者对之前电影的评价来推荐电影。
我使用Movie Lense数据集训练了模型。
library(recommenderlab)
Rec.model<-Recommender(MovieLense[1:400], method = "UBCF")
recommended.items.3 <- predict(Rec.model, MovieLense[500], n=10) #data from same dataset.
top3 <- bestN(recommended.items.3, n = 3)
没关系,但我想创建新的参与者,他们对Movie Lense数据集中的一些电影进行了评分。
那么如何将我刚刚创建的新稀疏矩阵(新用户[s])插入到Movie Lense数据集中,然后根据他们评分的内容推荐电影?
# new users
user <- factor(c(rep(1,4),rep(2,4)))
# selected items
item <- c("Leave It to Beaver (1997)", "Saint, The (1997)",
"Casper (1995)","My Fellow Americans (1996)")
item.r<- sample(item)
#ratings
a<- sample(5,4)
b<- sample(5,4)
#insert into data frame
newUser <- data.frame(user=user, item = c(item,item.r),rating=c(a,b))
#convert to sparse format
sparse_ratings <- sparseMatrix(i = as.numeric(newUser$user),
j = as.numeric(newUser$item),
x = as.numeric(newUser$rating),
dims = c(length(unique(newUser$user)),
length(unique(newUser$item))),
dimnames = list(levels(newUser$user),
levels(newUser$item)))
new <- new("realRatingMatrix", data = sparse_ratings)
as(new[1],'list') #see list
as(new[1],'matrix') # see matrix
as(new,'list')
str(new)
as(MovieLense[1],'matrix') #looks different
str(MovieLense) # look the same as str(new)
#How to combine MovieLense and new matrix together??