MBA in Python - 1
MBA in Python - 1
basket analysis?
M A R K E T B A S K E T A N A LY S I S I N P Y T H O N
Isaiah Hull
Economist
Selecting a bookstore layout
5 biography
... ...
5. Upsell products.
19 ction, biography
20 ction, biography
... ...
TID Transaction
0 biography, history
1 fiction
['biography', 'history']
218
5357
Isaiah Hull
Economist
Loading and preparing data
import pandas as pd
Multi-antecedent rule
{humor, travel} → {language}
Multi-consequent rule
{biography} → {history, language}
ction health
poetry travel
history language
biography humor
cooking
[('fiction', 'poetry'),
('fiction', 'history'),
...
('humor', 'travel'),
('humor', 'language')]
72
Isaiah Hull
Economist
Metrics and pruning
A metric is a measure of performance for rules.
{humor} → {poetry}
0.81
{ ction} → {travel}
0.23
number of transactions with items(s)
number of transactions
number of transactions with milk
total transactions
1 humor,language 6 humor
2 humor,biography,cooking 7 travel
4 travel 9 ction,biography
biography 0.2
cooking 0.2
fiction 0.3
health 0.1
history 0.1
humor 0.5
language 0.2
poetry 0.2
travel 0.4
dtype: float64
print(onehot.mean())
biography 0.2
cooking 0.2
... ...
travel 0.4
fiction+poetry 0.1
dtype: float64