3

I want to know how to get the absolute support and relative support of itemsets in python. Presently I have the following:

import pandas as  pd
import pyfpgrowth
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import apriori
from collections import Counter


dataset = [['a', 'b', 'c', 'd'],
              ['b', 'c', 'e', 'f'],
              ['a', 'd', 'e', 'f'],
              ['a', 'e', 'f'],
              ['b', 'd', 'f']
           ]
te = TransactionEncoder()
te_ary = te.fit(dataset).transform(dataset)
df = pd.DataFrame(te_ary, columns=te.columns_)
print (df)
#print support
print(apriori(df, min_support = 0.0))
#print frequent itemset
frequent_itemsets = apriori(df, min_support=0.6, use_colnames=True)
frequent_itemsets['length'] = frequent_itemsets['itemsets'].apply(lambda x: 
len(x))
frequent_itemsets
print ("frequent itemset at min support = 0.6")
print(frequent_itemsets)

but I do not know how to return the absolute support and relative support.

1 Answer 1

3

The relative support is part of your frequen_itemsets DataFrame. You can get it from:

frequent_itemsets['support']

And you can calculate the absolute support multiplying support by the number of baskets:

frequent_itemsets['support']*len(dataset)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.