tommyod/Efficient-Apriori

Code for count_all

Cap-7 opened this issue · 5 comments

Cap-7 commented

Can u pls explain the code of count_all?

Where is the code of count_all?

Sry count_full which is used to count the union of the lhs and rhs in the dataset.

count_full the total number of times the union of the left hand side and right hand side appear in the data set.

If you want a more detailed explanation, you're gonna have to ask a more detailed question. I don't fully understand what you're asking for here.

Can u hlp me with this..
how to find intersection of two rules?
if rule1 is {a, b} -> {c} and rule2 is {a} -> {c, d}

{a, b} -> {c} intersection {a} -> {c, d} means
the count of every time {a, b,c,d} appear together in a transaction...

Any idea how to get this???

This is a mathematical question @Andhu7. I don't see how what you describe above is an intersection of two rules.

I hope the following code can get you started.

from efficient_apriori import apriori
transactions = [('eggs', 'bacon', 'soup'),
                ('eggs', 'bacon', 'apple'),
                ('soup', 'bacon', 'banana')]
itemsets, rules = apriori(transactions, min_support=0.5,  min_confidence=1)
print(rules)  # [{eggs} -> {bacon}, {soup} -> {bacon}]

from functools import reduce
def intersection(rule1, rule2):
   # Here you must define what you believe an intersection is.
   # I have taken the union of the RHS and LHS of both rules,
   # since it complies with your example. It's obviously not an intersection.
   return reduce(set.union, (set(k) for k in (rule1.lhs, rule1.rhs, rule2.lhs, rule2.rhs)))

new_rule = intersection(rules[0], rules[1])

# Simply loop over the transactions and count
count = 0
for trans in transactions:
   if new_rule.issubset(set(trans)):
      count += 1

print(count) # Should print 1.

I'm going to close this issue. The purpose of Issues as they relate to this repository is to report bugs or suggest improvements to the software. The purpose of Issues is not to get help with general Python and mathematics, even if they relate to itemsets and the apriori algorithm.