Search code examples
rdata-miningaprioriarules

How can I constrain the apriori function in R to consider only specific value items in LHS?


In R, I am trying to use the apriori function for Association Rule Learning.

I have a data set like this:

A B C D E 

1 0 0 1 0

1 0 1 0 1

1 1 1 0 1

0 0 0 1 0

I am interested in cases where E = 1, which I can get by doing:

inspect( subset( rules.sorted, subset = rhs %pin% "E=1" ))

But I am also interested in cases only where the LHS contains '=1' conditions and not '=0'.

So, I don't want rules like:

{A=1,D=0} => {E=1}

I just want rules like

{A=1,C=1} => {E=1}

How can I achieve this in the LHS side? I could only gather how to constraint it to look for rules in specific column(s), but not for any column with specific value.


Solution

  • I had the same problem. The issue arises when you convert your data to a factor (like a couple people mentioned in the comments to another answer). When I converted my data.frame to a matrix and then to transactions, I had positive rules only in the output.