Association Rule Mining-Hands - On
Association Rule Mining-Hands - On
Association Rule Mining-Hands - On
Welcome to the first Hands On association rule mining. In this exercise , you will try out ASM regression using
mlxtend library that you have learnt in the course. We have created this Python Notebook with all the necessary
things needed for completing this exercise. You have to write your code in between the are mentioned
Start Code ¶
Your Code here
End Code
To run the code in each cell click on the cell and press shift + enter
Run the below cell to load the data on which you will be performing ASM. The data has the records of items
purcahed where each element of 'Data' refers to a single transaction
In [1]:
In [2]:
import pandas as pd
from mlxtend.preprocessing import OnehotTransactions
from mlxtend.frequent_patterns import apriori
https://2886795294-8888-host04-fresco.environments.katacoda.com/notebooks/ASM-hands_on.ipynb 1/4
11/9/2018 ASM-hands_on
In [13]:
Arm Band Bluetooth Headset Leather Pouch Mobile Cover Power Bank \
0 False False False False True
1 False True False True False
2 True False False True False
3 False False True False True
4 False True False True True
/home/scrapbook/.local/lib/python3.5/site-packages/mlxtend/preprocessing/one
hot.py:66: DeprecationWarning: OnehotTransactions has been deprecated and wi
ll be removed in future. Please use TransactionEncoder instead.
warnings.warn(msg, DeprecationWarning)
generate association rule for all the itemsets(frequent_itemsets) with minimum confidence 0.7
https://2886795294-8888-host04-fresco.environments.katacoda.com/notebooks/ASM-hands_on.ipynb 2/4
11/9/2018 ASM-hands_on
In [14]:
antecedents consequents \
0 (Mobile Cover, Power Bank) (Bluetooth Headset)
1 (Power Bank, Bluetooth Headset) (Mobile Cover)
2 (Mobile Cover, Arm Band) (Screen Guard)
3 (Screen Guard, Arm Band) (Mobile Cover)
4 (Arm Band) (Mobile Cover, Screen Guard)
5 (Travel Charger) (Screen Guard)
6 (Travel Charger) (Power Bank)
7 (Bluetooth Headset) (Mobile Cover)
8 (Leather Pouch) (Power Bank)
9 (Screen Guard, Travel Charger) (Power Bank)
10 (Power Bank, Travel Charger) (Screen Guard)
11 (Travel Charger) (Screen Guard, Power Bank)
12 (Leather Pouch, Power Bank) (Screen Guard)
13 (Leather Pouch, Screen Guard) (Power Bank)
14 (Leather Pouch) (Screen Guard, Power Bank)
15 (Arm Band) (Screen Guard)
16 (Leather Pouch) (Screen Guard)
17 (Arm Band) (Mobile Cover)
18 (Screen Guard, Bluetooth Headset) (Mobile Cover)
leverage conviction
0 0.12 inf
1 0.08 inf
2 0.04 inf
3 0.08 inf
4 0.12 inf
5 0.04 inf
6 0.08 inf
7 0.16 inf
8 0.08 inf
9 0.08 inf
https://2886795294-8888-host04-fresco.environments.katacoda.com/notebooks/ASM-hands_on.ipynb 3/4
11/9/2018 ASM-hands_on
10 0.04 inf
11 0.12 inf
12 0.04 inf
13 0.08 inf
14 0.12 inf
15 0.04 inf
16 0.04 inf
17 0.08 inf
18 0.08 inf
What is the consequent support value for Leather Pouch -> Screen Guard ?
What is the lift value for (Arm Band, Mobile Cover)->(Screen Guard) ?
In how many scenarios do you see 2 items (dualtons) in the antecedent set ?
assign the above abservations to respective variable in the cell below
In [15]:
In [ ]:
https://2886795294-8888-host04-fresco.environments.katacoda.com/notebooks/ASM-hands_on.ipynb 4/4