我当前在Windows机器上运行带有推荐器版本0.2-2的R-64bit(版本3.4.4)
下面是示例数据集
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='')))
将矩阵转换为binaryRatingMatrix
b <- as(m, "binaryRatingMatrix")
计算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))
)
计算预测的推荐项目“ topNList”(有错误)
as(predict(recom, 1, newdata = b, type = "topNList", n = 10), "list")
Error in match.arg(type) : 'arg' should be one of “topNList”
r <- Recommender(b, method = "AR")
as(predict(r, 1, newdata = b, type = "topNList", n = 10), "list")
$u1
character(0)
$u2
[1] "i10" "i2" "i5" "i6" "i9" "i8"
$u3
[1] "i4" "i6" "i9" "i8" "i3"
$u4
[1] "i9" "i8"
$u5
[1] "i7" "i3" "i2" "i10" "i4" "i5" "i6" "i1"
新编辑:在“ realRatingMatrix”上尝试了“ HybridRecommender”,它可以正常工作
data(Jester5k)
class(Jester5k)
[1] "realRatingMatrix"
attr(,"package")
[1] "recommenderlab"
system.time(
recom <- HybridRecommender(
Recommender(Jester5k, method = "POPULAR"),
Recommender(Jester5k, method = "IBCF"),
Recommender(Jester5k, method = "SVDF"),
Recommender(Jester5k, method = "UBCF"),
weights = c(.25, .25, .25, .25))
)
getList(predict(recom, 1:5, Jester5k, 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"