Apriori and Eclat: Market Basket Analysis
The one idea: Association rule mining finds patterns like "customers who buy diapers also buy beer" by counting how often item combinations occur together, then filtering for combinations that are both common (support) and predictive (confidence). Apriori and Eclat are two algorithms for finding those combinations without checking every possible one — they differ only in how they search, not in what a "good rule" means.
⚠️ The trap: A rule with 95% confidence sounds like a slam dunk. It isn't automatically one. **If the item on the right-hand side is already purchased 98% of the time by everyone, then a rule predicting it with 95% confidence is actually worse than doing nothing — you'd have been better off just recommending the popular item to every customer.** Confidence alone never tells you that; you need lift, which compares the rule to the base rate.
The setup: market basket analysis
Association rule learning starts with a very simple data shape: a list of transactions, where each transaction is just a set of items purchased together. No prices, no timestamps, no customer IDs — just "these items were in the same basket." The classic goal is to answer: which items tend to show up together often enough, and predictably enough, to act on — for a "customers who bought X also bought Y" recommendation, a shelf-placement decision, or a bundle promotion.
Here's a small grocery-store dataset we'll use for every calculation in this lesson — 10 transactions, 6 possible items:
transactions = [
['Bread', 'Milk'], # T1
['Bread', 'Diapers', 'Beer', 'Eggs'], # T2
['Milk', 'Diapers', 'Beer', 'Cola'], # T3
['Bread', 'Milk',…Keep reading: Apriori and Eclat
Unlock the full Machine Learning track — every lesson, the AI tutor, and full mock assessments.
- Full lesson content
- AI tutor for this section
- Practice questions