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.

jaco0646
  • 15,303
  • 7
  • 59
  • 83
olu
  • 31
  • 1
  • 4

1 Answers1

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)
Franco Piccolo
  • 6,845
  • 8
  • 34
  • 52