2015-01-15 42 views
1

我正在使用recommenderlab从UBCF和IBCF模型获取建议,并且一切似乎都正常工作(我得到了建议,而且它们似乎有意义)。我想解释为什么每个建议正在生产,所以我想获得用户(UBCF)和项目(IBCF)之间的相似之处。Recommnederlab - 从推荐器中提取相似度

我IBCF推荐器我可以看到相似性存储到推荐器结构(aux_recommneder @ model $ sim),但我不知道如何正确提取它们。我想选择特定项目并获得顶部x最相似的项目(用于构建推荐)。使用UBCF我想选择特定的用户并获得他们最相似的用户。

我IBCF推荐结构如下:

> str(aux_recommender) 
    Formal class 'Recommender' [package "recommenderlab"] with 5 slots 
     [email protected] method : chr "IBCF" 
     [email protected] dataType: atomic [1:1] realRatingMatrix 
     .. ..- attr(*, "package")= chr "recommenderlab" 
     [email protected] ntrain : int 7106 
     [email protected] model :List of 9 
     .. ..$ description   : chr "IBCF: Reduced similarity matrix" 
     .. ..$ sim     :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots 
     .. .. .. [email protected] i  : int [1:2644] 12 105 649 705 1207 1282 555 62 365 485 ... 
     .. .. .. [email protected] p  : int [1:1323] 0 6 6 7 7 7 7 12 13 13 ... 
     .. .. .. [email protected] Dim  : int [1:2] 1322 1322 
     .. .. .. [email protected] Dimnames:List of 2 
     .. .. .. .. ..$ : chr [1:1322] "1" "19" "22" "41" ... 
     .. .. .. .. ..$ : chr [1:1322] "1" "19" "22" "41" ... 
     .. .. .. [email protected] x  : num [1:2644] 0.71 0.766 0.834 0.663 0.919 ... 
     .. .. .. [email protected] factors : list() 
     .. ..$ k     : num 2 
     .. ..$ method    : chr "Pearson" 
     .. ..$ normalize   : chr "Z-score" 
     .. ..$ normalize_sim_matrix: logi FALSE 
     .. ..$ alpha    : num 0.5 
     .. ..$ na_as_zero   : logi FALSE 
     .. ..$ minRating   : num 2 
     [email protected] predict :function (model, newdata, n = 10, data = NULL, type = c("topNList", ratings"), ...) 

在我UBCF我甚至无法发现的相似的存储位置(如果是的话)。

我UBCF结构为:

> str(rec_ub) 
Formal class 'Recommender' [package "recommenderlab"] with 5 slots 
    [email protected] method : chr "UBCF" 
    [email protected] dataType: atomic [1:1] realRatingMatrix 
    .. ..- attr(*, "package")= chr "recommenderlab" 
    [email protected] ntrain : int 7106 
    [email protected] model :List of 7 
    .. ..$ description: chr "UBCF-Real data: contains full or sample of data set" 
    .. ..$ data  :Formal class 'realRatingMatrix' [package "recommenderlab"] with 2 slots 
    .. .. .. [email protected] data  :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots 
    .. .. .. .. .. [email protected] i  : int [1:2103234] 0 1 2 3 4 5 6 7 8 9 ... 
    .. .. .. .. .. [email protected] p  : int [1:1323] 0 6908 8602 9037 9546 14311 17869 18006 23693 24432 ... 
    .. .. .. .. .. [email protected] Dim  : int [1:2] 7106 1322 
    .. .. .. .. .. [email protected] Dimnames:List of 2 
    .. .. .. .. .. .. ..$ : chr [1:7106] "10034" "10042" "10048" "10069" ... 
    .. .. .. .. .. .. ..$ : chr [1:1322] "1" "19" "22" "41" ... 
    .. .. .. .. .. [email protected] x  : num [1:2103234] -0.371 0.465 -0.174 0.188 0.27 ... 
    .. .. .. .. .. [email protected] factors : list() 
    .. .. .. [email protected] normalize:List of 3 
    .. .. .. .. ..$ method : chr "Z-score" 
    .. .. .. .. ..$ row : logi TRUE 
    .. .. .. .. ..$ factors:List of 2 
    .. .. .. .. .. ..$ means: Named num [1:7106] 2.48 1.57 2.2 1.82 2.63 ... 
    .. .. .. .. .. .. ..- attr(*, "names")= chr [1:7106] "10034" "10042" "10048" "10069" ... 
    .. .. .. .. .. ..$ sds : Named num [1:7106] 1.287 0.928 1.134 0.934 1.377 ... 
    .. .. .. .. .. .. ..- attr(*, "names")= chr [1:7106] "10034" "10042" "10048" "10069" ... 
    .. ..$ method  : chr "Pearson" 
    .. ..$ nn   : num 2 
    .. ..$ sample  : logi FALSE 
    .. ..$ normalize : chr "Z-score" 
    .. ..$ minRating : num 2 
    [email protected] predict :function (model, newdata, n = 10, data = NULL, type = c("topNList", "ratings"), ...) 

我需要知道的是为什么,例如,项目102被推荐到用户10034.在IBCF应该是因为项目102它类似于其他项目用户评价很高(如果我们考虑2个社区,则可以是例如项目1和250)。我需要知道这些项目是什么?我如何知道项目102是因为项目1和250而被推荐的?我需要UBCF模型中的用户。

我会感谢一些帮助。

回答

1

不知道是否为时已晚,但你可以使用下面的代码的确切的IBCF相似:

similarity <- as.matrix([email protected]$sim)