pythonraprioriarules

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!


Solution

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