-1

my data set looks like this

A          B       C       D    PR1 PR2 PR3 PR4
Values  Values  Values  Values  0   1   0   0
Values  Values  Values  Values  1   0   0   0
Values  Values  Values  Values  0   0   1   0
Values  Values  Values  Values  0   0   0   1
Values  Values  Values  Values  0   1   0   0
Values  Values  Values  Values  1   0   0   0
Values  Values  Values  Values  0   0   1   0
Values  Values  Values  Values  0   0   0   1
Values  Values  Values  Values  0   1   0   0
Values  Values  Values  Values  1   0   0   0
Values  Values  Values  Values  0   0   1   0
Values  Values  Values  Values  0   0   0   1
Values  Values  Values  Values  0   1   0   0
Values  Values  Values  Values  1   0   0   0

I want to have only a,b,c and d columns in lhs and rhs must be only the columns PR1,PR2,PR3,PR4 containing a value 1. An eg of the result I am expecting is

lhs = {a,b}, RHS{PR1=1}
lhs= {b,c,d}, RHS {PR3 =1}

I have been using the code below, but am not getting the desired result

r <- apriori(b, parameter = list(supp = 0.1, conf = 0.9),              
             appearance = list(lhs = c("A","B","C","D")))

Can someone please provide a solution for this

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197

1 Answers1

1

"not getting the desired result" is not the best description of what went wrong. For example, it seems to work for me when lowering the minimum required confidence:

library(arules)
r <- apriori(b, parameter = list(supp = .2, conf = .2), 
                                 appearance=list(lhs=c("A","B","C","D")))
inspect(subset(r, rhs(r) %ain% "PR1" & lhs(r) %ain% c("A", "B")))
#    lhs          rhs   support   confidence lift
# 41 {A,B}     => {PR1} 0.2857143 0.2857143  1   
# 58 {A,B,C}   => {PR1} 0.2857143 0.2857143  1   
# 59 {A,B,D}   => {PR1} 0.2857143 0.2857143  1   
# 64 {A,B,C,D} => {PR1} 0.2857143 0.2857143  1  
inspect(subset(r, rhs(r) %ain% "PR1" & labels(lhs(r))=="{A,B}"))
#    lhs      rhs   support   confidence lift
# 41 {A,B} => {PR1} 0.2857143 0.2857143  1   
inspect(subset(r, labels(rhs(r))=="{PR3}" & labels(lhs(r))=="{B,C,D}"))
# 45 {B,C,D} => {PR3} 0.2142857 0.2142857  1 

Data:

b <- new("transactions"
    , data = new("ngCMatrix"
    , i = c(0L, 1L, 2L, 3L, 5L, 0L, 1L, 2L, 3L, 4L, 0L, 1L, 2L, 3L, 6L, 
0L, 1L, 2L, 3L, 7L, 0L, 1L, 2L, 3L, 5L, 0L, 1L, 2L, 3L, 4L, 0L, 
1L, 2L, 3L, 6L, 0L, 1L, 2L, 3L, 7L, 0L, 1L, 2L, 3L, 5L, 0L, 1L, 
2L, 3L, 4L, 0L, 1L, 2L, 3L, 6L, 0L, 1L, 2L, 3L, 7L, 0L, 1L, 2L, 
3L, 5L, 0L, 1L, 2L, 3L, 4L)
    , p = c(0L, 5L, 10L, 15L, 20L, 25L, 30L, 35L, 40L, 45L, 50L, 55L, 60L, 
65L, 70L)
    , Dim = c(8L, 14L)
    , Dimnames = list(NULL, NULL)
    , factors = list()
)
    , itemInfo = structure(list(labels = c("A", "B", "C", "D", "PR1", "PR2", "PR3", 
"PR4")), .Names = "labels", row.names = c(NA, -8L), class = "data.frame")
    , itemsetInfo = structure(list(transactionID = c("1", "2", "3", "4", "5", "6", 
"7", "8", "9", "10", "11", "12", "13", "14")), .Names = "transactionID", row.names = c(NA, 
-14L), class = "data.frame")
)
lukeA
  • 53,097
  • 5
  • 97
  • 100
  • Hello luke, thanks for your answer. I understand by lowering the thresholds I would get the expected results. I wanted to know if there are any means to get the solution expected without lowering the thresholds? – Madhwesh Srinivasan Jun 03 '16 at 06:31
  • No, I don't think there are any. – lukeA Jun 03 '16 at 07:59