tommyod/Efficient-Apriori

filters

Closed this issue · 2 comments

Thank you for this useful tool.
Can i specify the consequent of rules?
For example can i say i just want rules that their right hand is butter or cheese?

Hi @hgoudarzy. Yes you can, here's a minimal working example.

from efficient_apriori import apriori
transactions = [('eggs', 'bacon', 'soup'),
                ('eggs', 'bacon', 'apple'),
                ('soup', 'bacon', 'banana')]
itemsets, rules = apriori(transactions, min_support=0.1,  min_confidence=1)

# Print every rule with 'soup' in the RHS
for rule in rules:
    if 'soup' in rule.rhs:
        print(rule)

# Print every rule with 'soup' or 'eggs' in the RHS
for rule in rules:
    if ('soup' in rule.rhs) or ('eggs' in rule.rhs):
        print(rule)

# Print every rule where any item in 'items' occurs in the RHS
items = ('soup', 'bacon', 'banana')
for rule in rules:
    if any((item in rule.rhs) for item in items):
        print(rule)

Let me know if this works for you.

Thanks. it did work.