我目前正在使用R Recommendationerlab构建产品推荐,在计算完AR推荐器之后,我希望了解关联规则,但是我找不到为什么要从推荐对象中提取完整关联规则的原因。
下面是示例数据集
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")
使用培训数据创建基于用户的CF推荐器
r <- Recommender(getData(scheme, "train"), "AR")
在查看AR推荐对象r@model$rule_base
时,我发现“ rule_base”
Formal class 'Recommender' [package "recommenderlab"] with 5 slots
..@ method : chr "AR"
..@ dataType: chr "binaryRatingMatrix"
..@ ntrain : int 5
..@ model :List of 9
.. ..$ description : chr "AR: rule base"
.. ..$ rule_base :Formal class 'rules' [package "arules"] with 4 slots
.. .. .. ..@ lhs :Formal class 'itemMatrix' [package "arules"] with 3 slots
.. .. .. .. .. ..@ data :Formal class 'ngCMatrix' [package "Matrix"] with 5 slots
.. .. .. .. .. .. .. ..@ i : int [1:145] 1 1 1 1 2 0 0 0 5 5 ...
.. .. .. .. .. .. .. ..@ p : int [1:80] 0 1 2 3 4 5 6 7 8 9 ...
.. .. .. .. .. .. .. ..@ Dim : int [1:2] 10 79
.. .. .. .. .. .. .. ..@ Dimnames:List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. ..@ factors : list()
.. .. .. .. .. ..@ itemInfo :'data.frame': 10 obs. of 1 variable:
.. .. .. .. .. .. ..$ labels: chr [1:10] "i1" "i2" "i3" "i4" ...
.. .. .. .. .. ..@ itemsetInfo:'data.frame': 0 obs. of 0 variables
.. .. .. ..@ rhs :Formal class 'itemMatrix' [package "arules"] with 3 slots
.. .. .. .. .. ..@ data :Formal class 'ngCMatrix' [package "Matrix"] with 5 slots
.. .. .. .. .. .. .. ..@ i : int [1:79] 6 4 9 3 8 4 9 3 6 3 ...
.. .. .. .. .. .. .. ..@ p : int [1:80] 0 1 2 3 4 5 6 7 8 9 ...
.. .. .. .. .. .. .. ..@ Dim : int [1:2] 10 79
.. .. .. .. .. .. .. ..@ Dimnames:List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. ..@ factors : list()
.. .. .. .. .. ..@ itemInfo :'data.frame': 10 obs. of 1 variable:
.. .. .. .. .. .. ..$ labels: chr [1:10] "i1" "i2" "i3" "i4" ...
.. .. .. .. .. ..@ itemsetInfo:'data.frame': 0 obs. of 0 variables
.. .. .. ..@ quality:'data.frame': 79 obs. of 4 variables:
.. .. .. .. ..$ support : num [1:79] 0.2 0.2 0.2 0.2 0.4 0.4 0.4 0.4 0.4 0.4 ...
.. .. .. .. ..$ confidence: num [1:79] 1 1 1 1 1 1 1 1 1 1 ...
.. .. .. .. ..$ lift : num [1:79] 1.67 1.25 1.25 1.25 1.67 ...
.. .. .. .. ..$ count : num [1:79] 1 1 1 1 2 2 2 2 2 2 ...
.. .. .. ..@ info :List of 4
.. .. .. .. ..$ data : symbol data
.. .. .. .. ..$ ntransactions: int 5
.. .. .. .. ..$ support : num 0.1
.. .. .. .. ..$ confidence : num 0.8
.. ..$ support : num 0.1
.. ..$ confidence : num 0.8
.. ..$ maxlen : num 3
.. ..$ sort_measure : chr "confidence"
.. ..$ sort_decreasing: logi TRUE
.. ..$ apriori_control:List of 1
.. .. ..$ verbose: logi FALSE
.. ..$ verbose : logi FALSE
..@ predict :function (model, newdata, n = 10, data = NULL, type = c("topNList", "ratings", "ratingMatrix"), ...)
答案 0 :(得分:1)
您可以使用
#Convert rules into data frame
rules3 = as(rules, "data.frame")