mhahsler / recommenderlab

recommenderlab - Lab for Developing and Testing Recommender Algorithms - R package
213 stars 61 forks source link

Unable to predict "topNList" using "HybridRecommender" on "binaryRatingMatrix" #29

Closed yckoong closed 5 years ago

yckoong commented 5 years ago

Hi @mhahsler, I'm current running R-64bit (version 3.4.4) on windows machine with recommenderlab version 0.2-2 . I got an issue when predict recommendation "topNList" using "HybridRecommender" on "binaryRatingMatrix". Below are my code:-

1) Tried predict using "HybridRecommender" on "binaryRatingMatrix" (return error)

# Below is the sample dataset
m <- matrix(sample(c(0,1), 50, replace=TRUE), nrow=5, ncol=10,
            dimnames=list(users=paste("u", 1:5, sep=''),
                           items=paste("i", 1:10, sep='')))

# Convert matrix into binaryRatingMatrix
b <- as(m, "binaryRatingMatrix")

# Compute HybridRecommender
system.time(
     recom <- recommenderlab::HybridRecommender(
         Recommender(b, method = "AR"),
         Recommender(b, method = "IBCF"),
         Recommender(b, method = "POPULAR"),
         Recommender(b, method = "UBCF"),
         weights = c(.25, .25, .25, .25))
)

# Compute predicted recommendation items "topNList" (return error)
getList(predict(recom, 1:5, data = b, type = "topNList", n = 5, ))

Error in match.arg(type) : 'arg' should be one of “topNList”
In addition: Warning message:
In data[newdata, , drop = FALSE] : drop not implemented for ratingMatrix!

2) Tried predict using "HybridRecommender" on "realRatingMatrix", it work as well with no prediction issue

# Load sample dataset
data(Jester5k)

# check dataset class
class(Jester5k)
[1] "realRatingMatrix"
attr(,"package")
[1] "recommenderlab"

# Compute HybridRecommender
system.time(
  recom2 <- HybridRecommender(
      Recommender(Jester5k, method = "POPULAR"),
      Recommender(Jester5k, method = "IBCF"),
      Recommender(Jester5k, method = "SVDF"),
      Recommender(Jester5k, method = "UBCF"),
      weights = c(.25, .25, .25, .25))
)

# Predict recommendation (works well with no prediction issue)
getList(predict(recom2, 1:5, data = Jester5k, type = "topNList", n = 5))

[[1]]
[1] "j84" "j85" "j83" "j82" "j81"

[[2]]
[1] "j89" "j93" "j76" "j81" "j88"

[[3]]
character(0)

[[4]]
character(0)

[[5]]
[1] "j80"  "j81"  "j100" "j72"  "j89" 

Warning message:
In data[newdata, , drop = FALSE] : drop not implemented for ratingMatrix!

Hope to hear from you!

mhahsler commented 5 years ago

AR and POPULAR were not able to create ratings for binary data. A version that can do this is now on GitHub. This will be part of the next release.

Please check the new version. I did not have enough time to do thorough testing.

yckoong commented 5 years ago

Hi @mhahsler , glad to hear from you and thanks for the bug fixed. I'm excited to test the new RECOM_AR.R and RECOM_POPULAR.R code, but i couldn't find a way to update the new version code into existing recommenderlab on my machine. Could you lead me?

mhahsler commented 5 years ago

From the Github page for recommenderlab. Hope this works.

Current development version: Download package from AppVeyor or install from GitHub (needs devtools).

library("devtools") install_github("mhahsler/recommenderlab")

yckoong commented 5 years ago

@mhahsler thanks for the guidance, tested the latest development version, the prediction for hybridrecommender on "binaryRatingMatrix" works smoothly :)

mhahsler commented 5 years ago

Great! Thanks for testing.