I have a dataset:
[['Apple', 'Beer', 'Chicken', 'Rice'],
['Apple', 'Beer', 'Rice'],
['Apple', 'Beer'],
['Apple', 'Bananas']]
I am using the frequent itemsets tools, specifically apriori, to find frequent datasets. I convert to a OneHotDataset, then to a Data Frame:
oht = OnehotTransactions()
oht_ary = oht.fit(tempList).transform(tempList)
oht_ary
df = pd.DataFrame(oht_ary, columns=oht.columns_)
df
Then I use the Apriori function:
frequent_itemsets = apriori(df, min_support=0.01, use_colnames=True)
I see this table, which is what I expect:
support itemsets
0 1.00 [Apple]
1 0.25 [Bananas]
2 0.75 [Beer]
3 0.25 [Chicken]
4 0.50 [Rice]
5 0.25 [Apple, Bananas]
6 0.75 [Apple, Beer]
7 0.25 [Apple, Chicken]
8 0.50 [Apple, Rice]
9 0.25 [Beer, Chicken]
10 0.50 [Beer, Rice]
11 0.25 [Chicken, Rice]
12 0.25 [Apple, Beer, Chicken]
13 0.50 [Apple, Beer, Rice]
14 0.25 [Apple, Chicken, Rice]
15 0.25 [Beer, Chicken, Rice]
16 0.25 [Apple, Beer, Chicken, Rice]
The question I have is, is there any way to print a suppport "count" of occurrences of the datasets-meaning how many times that itemset appears in the transactions? One thing I messed around with from the mlxtend site was this being added to add an additional column of length but couldn't get a count piece:
frequent_itemsets['length'] = frequent_itemsets['itemsets'].apply(lambda x: len(x))
EDIT: Ok I think I am confusing folks. What I would like to see is:
support itemsets count
0 1.00 [Apple] 4
1 0.25 [Bananas] 1
2 0.75 [Beer] 3
3 0.25 [Chicken] 1
I guess I could just create a column that uses the total support and multiplies by the relative support, but was looking for a more systematic way to do it.
from collections import Counter
Counter(tempList)
$\endgroup$Counter
$\endgroup$