Introduction to Market Basket Analysis
What is Market Basket Analysis?
- Identify products frequently purchased together.
- Biography and history
- Fiction and poetry
- Construct recommendations based on these findings.
- Place biography and history sections together
- Keep fiction and history apart
The Use Cases of Market Basket Analysis
- Build Netflix-style recommendations engine
- Improve product recommendations on an e-commerce store
- Cross-sell products in a retail setting
- Improve inventory management
- Upsell products
Association Rules
- {antecedent} → {consequent}
- Multi-antecedent Rule
- {humor, travel}→{language}
- Multi-consequent Rule
- {biography}→{history, language}
Generate Rules with itertools
from itertools import permutations
# Extract unique items
flattened = [item for transaction in transactions for item in transaction
items = list(set(flattened))
# Compute and print rules
rules = list(permutations(items, 2))
print(rules)
mlxtend Library