Generating 2-itemset rules with Arules in R

Question:

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}.

  • In arules, is it possible to restrict rules such that LHS and RHS only has a
    single item? (i.e. Avoiding rules {milk, nappies} => {beer})

  • Alternatively, is the rule {milk, nappies} => {beer} equivalent to
    saying {milk} => {beer} and {nappies} => {beer}?

Any help is appreciated!

Asked By: kami

||

Answers:

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}.

Answered By: Franziska W.

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))
Answered By: SamMar
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.