Demo on this site · 2020, rebuilt 2026
Market-basket analysis (Apriori)
Association rules on 7,501 real shop transactions: which items are bought together, with support, confidence and lift, now correct and fast.
At a glance
- Transactions
- Clean
- Frequent itemsets
- Rules by lift
Context
The original demo timed out on App Engine, counted filler "0" values as items and showed some rules the wrong way round.
Problem
Make the rules correct and the demo fast enough to run on a small instance.
My role
Analysis and implementation.
Approach and architecture
- Load all columns as text and drop blanks, so fillers never become items
- One row per ordered rule (antecedent → consequent), strongest lift first
- Cache the built-in datasets; validate pasted input
- Tests against hand-checked rules
Stack
- Python
- pandas
- apyori
- Flask
Outcome
- Default request: 4.7 s → 0.36 s
- Rule direction fixed (pasta → escalope, confidence 0.373)
- No crash on single-item records