Reputation: 3
I have a large binary data set where I wish to run an apriori algorithm in R. The problem is at the algorithm is making rules of all the 0's, where I only wish to look at the 1's. As for example get these rules:
lhs rhs support confidence lift count
[1] {SPA=0,SPD=0,SPE=0,SPF=1,SPJ=0} => {SPC=0} 0.2036065 0.9866727 1.0174854 6515
[2] {SPA=0,SPD=0,SPE=0,SPF=1} => {SPC=0} 0.2163885 0.9864653 1.0172715 6924
[3] {SPA=0,SPD=0,SPF=1,SPJ=0} => {SPC=0} 0.2070754 0.9852788 1.0160479 6626
Does anyone know how to only look for the rules where the variables are 1 and not 0? Thank you!
Upvotes: 0
Views: 157
Reputation: 3075
The easiest way to fix this is to make the matrix logical before you create the transactions. For matrix m
you can do the following:
storage.mode(m) <- "logical"
trans <- as(m, transactions)
Upvotes: 0
Reputation: 37641
You can control this using the appearance
argument to apriori
. Since you do not provide data, I will use the built-in Adult data as an example, but I think that you need to add appearance=list(rhs = "SPC=1")
to your apriori statement.
I will generate only rules for which the rhs is native-country=United-States
rules <- apriori(Adult,
parameter = list(supp = 0.4, conf = 0.6,
minlen=2, target = "rules"),
appearance=list(rhs = "native-country=United-States")
)
inspect(rhs(rules[1:5]))
items
[1] {native-country=United-States}
[2] {native-country=United-States}
[3] {native-country=United-States}
[4] {native-country=United-States}
[5] {native-country=United-States}
I thought that you only wanted SPC=1 on the rhs. Based on your comments, I now think that you want to generate rules that contain no XYZ=0 items at all. You can also get this with appearance
. First identify the possible items with XYZ=0, then use appearance to exclude these. I do not know what your variables are called, so I am calling the transactions TransactionData
## identify items to exclude
excluded <- grep("=0", itemLabels(TransactionData), value = TRUE)
Then add this to your apriori
statement.
appearance=list(none = excluded)
Upvotes: 0