i'm current construct product recommendation using R recommenderlab, after compute AR recommender, i'm hoping to understand the association rules, but i couldn't found any why to extract the complete association rules from the recommender object.

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")

create a user-based CF recommender using training data

r <- Recommender(getData(scheme, "train"), "AR")

Looking into the AR recommender object [email protected]$rule_base i found "rule_base"

Formal class 'Recommender' [package "recommenderlab"] with 5 slots
  [email protected] method  : chr "AR"
  [email protected] dataType: chr "binaryRatingMatrix"
  [email protected] ntrain  : int 5
  [email protected] model   :List of 9
  .. ..$ description    : chr "AR: rule base"
  .. ..$ rule_base      :Formal class 'rules' [package "arules"] with 4 slots
  .. .. .. [email protected] lhs    :Formal class 'itemMatrix' [package "arules"] with 3 slots
  .. .. .. .. .. [email protected] data       :Formal class 'ngCMatrix' [package "Matrix"] with 5 slots
  .. .. .. .. .. .. .. [email protected] i       : int [1:145] 1 1 1 1 2 0 0 0 5 5 ...
  .. .. .. .. .. .. .. [email protected] p       : int [1:80] 0 1 2 3 4 5 6 7 8 9 ...
  .. .. .. .. .. .. .. [email protected] Dim     : int [1:2] 10 79
  .. .. .. .. .. .. .. [email protected] Dimnames:List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. [email protected] factors : list()
  .. .. .. .. .. [email protected] itemInfo   :'data.frame':  10 obs. of  1 variable:
  .. .. .. .. .. .. ..$ labels: chr [1:10] "i1" "i2" "i3" "i4" ...
  .. .. .. .. .. [email protected] itemsetInfo:'data.frame':  0 obs. of  0 variables
  .. .. .. [email protected] rhs    :Formal class 'itemMatrix' [package "arules"] with 3 slots
  .. .. .. .. .. [email protected] data       :Formal class 'ngCMatrix' [package "Matrix"] with 5 slots
  .. .. .. .. .. .. .. [email protected] i       : int [1:79] 6 4 9 3 8 4 9 3 6 3 ...
  .. .. .. .. .. .. .. [email protected] p       : int [1:80] 0 1 2 3 4 5 6 7 8 9 ...
  .. .. .. .. .. .. .. [email protected] Dim     : int [1:2] 10 79
  .. .. .. .. .. .. .. [email protected] Dimnames:List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. [email protected] factors : list()
  .. .. .. .. .. [email protected] itemInfo   :'data.frame':  10 obs. of  1 variable:
  .. .. .. .. .. .. ..$ labels: chr [1:10] "i1" "i2" "i3" "i4" ...
  .. .. .. .. .. [email protected] itemsetInfo:'data.frame':  0 obs. of  0 variables
  .. .. .. [email protected] 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 ...
  .. .. .. [email protected] 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
  [email protected] predict :function (model, newdata, n = 10, data = NULL, type = c("topNList", "ratings", "ratingMatrix"), ...)  

Question: how can i extract the association rules from recommender object as data frame?

  • Get association rules dataframe with columns (LHS, RHS, support, confidence, lift, count)

1 Answers

1
Hunaidkhan On Best Solutions

you can use

#Convert rules into data frame
rules3 = as(rules, "data.frame")