I have the following table:
https://i.redd.it/5szak6k1mhe31.png
I need to perform fp growth so that the ‘Student’ tuple in ‘Category’ and ‘Profession’ are considered separately and I can get the pattern [10-20], [Student], [Student]. The code i am using gives me support along with the patterns and it considers ‘Student’ in all the columns as same, how can extract only the patterns from this code and also get the pattern mentioned above?
I have the following code:
dataset = [[’10-20′, ‘Student’, ‘Student’, ‘Chicago’],
[’30-40′, ‘Adult’, ‘Unemployed’, ‘Chicago’],
[’30-40′, ‘Adult’, ‘Finance’, ‘Washington’],
[’10-20′, ‘Student’, ‘Student’, ‘Boston’]]
import pandas as pd
from mlxtend.preprocessing import TransactionEncoder
te = TransactionEncoder()
te_ary = te.fit(dataset).transform(dataset)
df = pd.DataFrame(te_ary, columns=te.columns_)
df
print(df)
from mlxtend.frequent_patterns import fpgrowth
print(fpgrowth(df, min_support=0.2))
print(fpgrowth(df, min_support=0.2, use_colnames=True))
Current output:
support itemsets
0 0.50 (Student)
1 0.50 (Chicago)
2 0.50 (10-20)
3 0.50 (Adult)
4 0.50 (30-40)
5 0.25 (Unemployed)
6 0.25 (Washington)
7 0.25 (Finance)
8 0.25 (Boston)
9 0.25 (Chicago, Student)
10 0.50 (10-20, Student)
11 0.25 (10-20, Chicago)
12 0.25 (10-20, Chicago, Student)
13 0.25 (Chicago, Adult)
14 0.50 (30-40, Adult)
15 0.25 (30-40, Chicago)
16 0.25 (30-40, Chicago, Adult)
17 0.25 (30-40, Unemployed)
18 0.25 (Unemployed, Adult)
19 0.25 (Chicago, Unemployed)
20 0.25 (30-40, Unemployed, Adult)
21 0.25 (30-40, Chicago, Unemployed)
22 0.25 (Chicago, Unemployed, Adult)
23 0.25 (30-40, Chicago, Unemployed, Adult)
24 0.25 (Washington, 30-40)
25 0.25 (Washington, Adult)
26 0.25 (Washington, 30-40, Adult)
27 0.25 (Washington, Finance)
28 0.25 (30-40, Finance)
29 0.25 (Finance, Adult)
30 0.25 (Washington, 30-40, Finance)
31 0.25 (Washington, Finance, Adult)
32 0.25 (30-40, Finance, Adult)
33 0.25 (Washington, 30-40, Finance, Adult)
34 0.25 (10-20, Boston)
35 0.25 (Student, Boston)
36 0.25 (10-20, Student, Boston)
>>>