Tomas Greif
Tomas Greif

Reputation: 22623

Post-processing of rules from arules

Is there a way how more than one level of single variable gets used in single rule generated by apriori in arules package?

Consider the following example:

df <- read.table(header = TRUE, text = '
V1 V2 V3
a d x 
a d x           
a d y        
b d x       
b d x       
b d y
a e y
a e y
a e x
b e y
b e y
b e x
c d y
')

library(arules)    
rules <- apriori(df, 
                 parameter = list(support= 0.001, confidence = 0.5, target = "rules"),
                 appearance = list(rhs=c("V3=x"), default = 'lhs'))
inspect(sort(rules, decreasing = TRUE, by = "confidence"))

Output>

  lhs       rhs      support confidence     lift
1 {V1=a,                                        
   V2=d} => {V3=x} 0.1538462  0.6666667 1.444444
2 {V1=b,                                        
   V2=d} => {V3=x} 0.1538462  0.6666667 1.444444
3 {V2=d} => {V3=x} 0.3076923  0.5714286 1.238095
4 {V1=a} => {V3=x} 0.2307692  0.5000000 1.083333
5 {V1=b} => {V3=x} 0.2307692  0.5000000 1.083333

In this example, it would helpful if I get rule {V1=a,b,V2=d}. Some other tools (e.g. LISp-Miner) can generate rules where more than one level of variable is used.

Upvotes: 0

Views: 276

Answers (1)

Michael Hahsler
Michael Hahsler

Reputation: 3050

arules follows the standard association rule mining literature and does not aggregate items in this way. Itemsets do either contain an item or not. So you are stuck with two rules unless you manually add an artificial item V1=aORb.

Upvotes: 1

Related Questions