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.
How can I constrain the apriori function in R to consider only specific value items in LHS?
-
14-10-2022 - |
Pergunta
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.
Solução
Outras dicas
As you already noted, if you want E=1
on the right hand side, just filter your data.
By default, association rule mining should give you only positive rules, aka A => B
.
Usually, if you wanted to have negative rules, you would have to add negated symbols to your data, i.e. ANOT=1
when A=0
.
Are you sure that you aren't just misinterpreting the output?