kami
kami

Reputation: 361

Generating 2-itemset rules with Arules in R

I'm using Arules library in R to generate rules:

rules = apriori(data = dataset, parameter = list(support = 0.001, confidence = 0.6, minlen=2))

I understand the minlen=2 avoids rules of the form {} => {beer}.

Any help is appreciated!

Upvotes: 1

Views: 284

Answers (2)

SamMar
SamMar

Reputation: 1

It's an old question, but some future viewer may use this answer:

You can set maxlen parameter as 2.

    rules = apriori(data = dataset, parameter = list(support = 0.001, 
    confidence = 0.6, minlen=2, maxlen=2))

Upvotes: 0

Franziska W.
Franziska W.

Reputation: 356

I would filter the rules for rules having exactly one item on the LHS.

rules <- rules[sapply(
  1:length(rules)
  ,function(x) length(as(rules@lhs, "list")[[x]])) == 1];

I think, assuming conditional independence of {beer} and {milk}, the rule {milk, nappies} => {beer} is equivalent to saying {nappies} => {beer}, and assuming conditional independence of {beer} and {nappies}, the rule {milk, nappies} => {beer} is equivalent to the rule {milk} => {beer}.

Upvotes: 1

Related Questions