首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在推荐实验室中使用userid进行预测

在推荐实验室中使用userid进行预测
EN

Stack Overflow用户
提问于 2018-12-19 12:27:26
回答 1查看 515关注 0票数 2

我有一个相当简单的推荐问题:我希望在R中使用recommenderlab构建一个混合推荐程序,在这里,我推荐MovieLense数据集中已经喜欢的电影,以及流行电影和一些随机电影。

代码语言:javascript
复制
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)
)

当我训练了这个模型后,我想用userId“预测”给定用户的电影。Recommenderlab文档表明,只要用户in在培训数据中,这是可能的。但是,当我尝试在userid中使用newdata进行预测时,会得到以下错误消息:

代码语言:javascript
复制
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.

公平地说,我尝试用一个向量:

代码语言:javascript
复制
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.

不知道这个错误信息是什么意思。有人知道吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-19 13:59:37

您只需要从培训数据集中精确地说明您正在向用户推荐项目,如下所示:

代码语言:javascript
复制
> as(predict(recom, 1, data = train), "list")
$`1`
 [1] "Hearts and Minds (1996)"                     "Boys, Les (1997)"                            "Great Day in Harlem, A (1994)"              
 [4] "Dangerous Beauty (1998)"                     "Tough and Deadly (1995)"                     "Two or Three Things I Know About Her (1966)"
 [7] "Santa with Muscles (1996)"                   "Margaret's Museum (1995)"                    "Brassed Off (1996)"                         
[10] "Thousand Acres, A (1997)"                   

> as(predict(recom, 1:10, data = train), "list")
$`1`
 [1] "Dangerous Beauty (1998)"                     "Great Day in Harlem, A (1994)"               "Hearts and Minds (1996)"                    
 [4] "Boys, Les (1997)"                            "Santa with Muscles (1996)"                   "Two or Three Things I Know About Her (1966)"
 [7] "Tough and Deadly (1995)"                     "Saint of Fort Washington, The (1993)"        "Whole Wide World, The (1996)"               
[10] "Margaret's Museum (1995)"                   

$`5`
 [1] "Boys, Les (1997)"                            "Two or Three Things I Know About Her (1966)" "Santa with Muscles (1996)"                  
 [4] "Dangerous Beauty (1998)"                     "Great Day in Harlem, A (1994)"               "Whole Wide World, The (1996)"               
 [7] "Hearts and Minds (1996)"                     "Brassed Off (1996)"                          "Saint of Fort Washington, The (1993)"       
[10] "Celestial Clockwork (1994)"                 

$`6`
 [1] "Dangerous Beauty (1998)"                     "Two or Three Things I Know About Her (1966)" "Santa with Muscles (1996)"                  
 [4] "Tough and Deadly (1995)"                     "Brassed Off (1996)"                          "Crooklyn (1994)"                            
 [7] "Great Day in Harlem, A (1994)"               "Hearts and Minds (1996)"                     "Saint of Fort Washington, The (1993)"       
[10] "Boys, Les (1997)"                           

$`7`
 [1] "Two or Three Things I Know About Her (1966)" "Tough and Deadly (1995)"                     "Santa with Muscles (1996)"                  
 [4] "Dangerous Beauty (1998)"                     "Hearts and Minds (1996)"                     "Great Day in Harlem, A (1994)"              
 [7] "Boys, Les (1997)"                            "Brassed Off (1996)"                          "Margaret's Museum (1995)"                   
[10] "Crooklyn (1994)"                            

$`10`
 [1] "Dangerous Beauty (1998)"                     "Great Day in Harlem, A (1994)"               "Hearts and Minds (1996)"                    
 [4] "Tough and Deadly (1995)"                     "Two or Three Things I Know About Her (1966)" "Boys, Les (1997)"                           
 [7] "Santa with Muscles (1996)"                   "Brassed Off (1996)"                          "Margaret's Museum (1995)"                   
[10] "Crooklyn (1994)"                            

$`11`
 [1] "Two or Three Things I Know About Her (1966)" "Hearts and Minds (1996)"                     "Great Day in Harlem, A (1994)"              
 [4] "Tough and Deadly (1995)"                     "Brassed Off (1996)"                          "Dangerous Beauty (1998)"                    
 [7] "Boys, Les (1997)"                            "Santa with Muscles (1996)"                   "Thousand Acres, A (1997)"                   
[10] "Horse Whisperer, The (1998)"                

$`13`
 [1] "Santa with Muscles (1996)"        "Brassed Off (1996)"               "Tough and Deadly (1995)"          "Boys, Les (1997)"                
 [5] "Thousand Acres, A (1997)"         "Margaret's Museum (1995)"         "Total Eclipse (1995)"             "Love! Valour! Compassion! (1997)"
 [9] "Withnail and I (1987)"            "Prefontaine (1997)"              

$`15`
 [1] "Two or Three Things I Know About Her (1966)" "Boys, Les (1997)"                            "Great Day in Harlem, A (1994)"              
 [4] "Tough and Deadly (1995)"                     "Dangerous Beauty (1998)"                     "Saint of Fort Washington, The (1993)"       
 [7] "Santa with Muscles (1996)"                   "Hearts and Minds (1996)"                     "Celestial Clockwork (1994)"                 
[10] "Whole Wide World, The (1996)"               

$`16`
 [1] "Great Day in Harlem, A (1994)"               "Dangerous Beauty (1998)"                     "Hearts and Minds (1996)"                    
 [4] "Two or Three Things I Know About Her (1966)" "Boys, Les (1997)"                            "Santa with Muscles (1996)"                  
 [7] "Tough and Deadly (1995)"                     "Brassed Off (1996)"                          "Crooklyn (1994)"                            
[10] "Thousand Acres, A (1997)"                   

$`18`
 [1] "Great Day in Harlem, A (1994)"               "Two or Three Things I Know About Her (1966)" "Dangerous Beauty (1998)"                    
 [4] "Hearts and Minds (1996)"                     "Santa with Muscles (1996)"                   "Tough and Deadly (1995)"                    
 [7] "Boys, Les (1997)"                            "Whole Wide World, The (1996)"                "Margaret's Museum (1995)"                   
[10] "Saint of Fort Washington, The (1993)" 

否则,我们不知道您指的是什么用户的预测函数。

您还可以对测试数据进行如下预测:

代码语言:javascript
复制
> as(predict(recom, test), "list")
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53851262

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档