-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrequentitemset.py
29 lines (20 loc) · 1 KB
/
frequentitemset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pandas as pd
from mlxtend.frequent_patterns import apriori
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import association_rules
df=pd.read_csv("D:\\IST paper\\frequent itemset\\total occurence.csv")
#print(df['commentid'])
#print(df)
#print(apriori(df, min_support=0.5))
#df = pd.DataFrame(te_ary, columns=te.columns_)
frequent_itemsets = apriori(df, min_support=0.2, use_colnames=True)
#print (frequent_itemsets.rank(ascending=False))
# print (frequent_itemsets)
#df['rank'] = df.groupby('cust_ID')['transaction_count'].rank(ascending=False)
# lists of columns where value is 1 per row
# cols = df.dot(df.columns).map(set).values.tolist()
# # use sets to see which rows are a superset of the sets in cols
# set_itemsets = map(set,frequent_itemsets.itemsets.values.tolist())
# frequent_itemsets['indices'] = [[ix for ix,j in enumerate(cols) if i.issubset(j)]
# for i in set_itemsets]
print(frequent_itemsets)