Why this session exists
Session 1 said unsupervised learning does three things to an unlabeled pile: group similar things, compress features, and find what goes together. The first two are done. The third works on a different unit - not the customer but the basket - and it powers the most visible retail analytics there is: "customers who bought this also bought...". The field's founding legend is the beer-and-diapers story: a supermarket supposedly discovered that young fathers buying diapers also grabbed beer, and moved the shelves accordingly. The story is very possibly apocryphal - nobody has ever produced the original analysis - but it survives because it captures the promise perfectly: co-occurrence patterns, mined from receipts nobody labeled, that a human merchandiser would never have guessed. Today you learn the three numbers that separate the real patterns from the folklore.
The three numbers of a rule 8 min live
A rule has the shape "if the basket has A, then it also has C" - antecedent, consequent. Every mined rule carries three numbers, and each answers a different question: support asks how common the pair is, confidence asks how reliable the if-then is, and lift asks whether the pairing beats plain chance. You need all three because each one alone can be gamed.
LiveThe arithmetic, worked by hand4 min▶
Toy shop, 100 baskets. Item A appears in 20 baskets, item C appears in 25, and 10 baskets contain both. The rule A → C:
| Number | Computation | Value | What it just told you |
|---|---|---|---|
| Support | 10 both ÷ 100 baskets | 10% | one basket in ten carries the pair - common enough to matter |
| Confidence | 10 both ÷ 20 with A | 50% | half of A's buyers also take C - the if-then is fairly reliable |
| C's base rate | 25 with C ÷ 100 | 25% | the chance ANY basket has C, ignoring A entirely |
| Lift | 50% ÷ 25% | 2.0 | A's buyers take C at twice the base rate - a real pull, not chance |
Two things to lock in. Confidence is directional: conf(A→C) = sup(A∪C) / sup(A), so flipping the rule changes the denominator - C→A here scores 10 ÷ 25 = 40%, a different number for a different claim. Lift is symmetric and centered on 1: lift 1 means A and C are independent, above 1 they attract, below 1 they actively avoid each other - a rule with lift 0.4 is telling you buyers of A do NOT buy C, which is merchandising information too.
Self-studyDirectionality in practice: the arrow picks the inbox2 min▶
Because confidence divides by the antecedent, the two directions of one pairing are two different campaigns. In the toy above, A→C scores 50% confidence while C→A scores 40% - same pair, same lift, different reach. The direction you ship is the direction whose antecedent you can act on: a cross-sell email goes to the people who already bought the IF side, so A→C at 50% means half the A-buyers you email are already inclined toward C. Flip the arrow and you are emailing C-buyers with a weaker claim. Lift tells you the pair is real; the confidence pair tells you which side of it to stand on. Check both directions before drafting anything - it is one extra division.
Self-studyWhy the basket, not the customer2 min▶
Notice the unit change: sessions 1-7 described customers (one row each, RFM); today's rows are baskets - one receipt, a set of items, no identity required. That is a feature, not a limitation: basket mining works on anonymous transactions, needs no customer history, and answers merchandising questions (placement, bundles) that segmentation cannot. The two views compose: a win-back email to lapsed big spenders (session 7) can carry the cross-sell the basket rules suggest (today). Same pile of unlabeled data, two lenses, one campaign.
Why lift is the honest column 6 min live
Here is the trap that catches every first-time basket miner: a rule can have high confidence purely because the consequent is popular with everyone. If 70% of all baskets contain gift wrap, then "anything → gift wrap" scores 70% confidence - beanies, belts, returns of socks, all of them "predict" gift wrap at 70%. The if-part contributed nothing. Confidence flatters popular items; lift divides that popularity back out. That is the whole reason lift exists.
LiveThe reading order: lift first, support as sanity check3 min▶
The practitioner's reading order for a rule table:
Sort by lift - it is the column that measures surprise, and surprise is where the unmined money is. A merchandiser already knows the popular items.
Sanity-check support before believing anything. A lift of 20 computed on 3 baskets is noise wearing a crown - tiny denominators produce spectacular ratios. If the pair barely occurs, the rule is an anecdote, not a pattern. Chase lift, but only where support says the evidence is thick enough to stand on.
Then read confidence for operations: once lift says the pull is real and support says it is common, confidence tells you what fraction of A-buyers your cross-sell will actually reach.
LiveApriori, decoded in one paragraph2 min▶
How does a machine find these rules without checking every possible item combination (which explodes combinatorially)? Apriori's one clever idea: count frequent itemsets first, and prune the rare ones early - because if {sneakers} alone is rare, then {sneakers, socks} cannot possibly be frequent, so entire branches of the search die without being counted. Count singles, keep the frequent; count pairs built only from frequent singles; keep going until nothing survives; then derive the if-then rules from the surviving sets. Clever counting, not magic. Its faster sibling fpgrowth reaches the same rules through a compressed tree structure - same output, better engineering - and both ship in mlxtend.
Self-studyThe knobs: minimum support and minimum confidence2 min▶
Real mining runs need thresholds, or the rule table drowns you. The standard workflow sets them in this order:
| Knob | What it does | How to think about it |
|---|---|---|
| min support | drops itemsets that occur too rarely to trust | the evidence floor - set it first; it is also what makes apriori's pruning bite |
| min confidence | drops if-thens that are too unreliable to act on | the operations floor - below it, the cross-sell reaches too few A-buyers to bother |
| lift filter | drops rules that merely restate popularity | applied last, on the surviving table - the honesty pass from part 2 |
Set the floors too high and real niche pairings vanish; too low and the table fills with three-basket anecdotes. Practitioners iterate: mine, eyeball, adjust, re-mine. The knobs are judgment calls, which is exactly why the three-number fluency from part 1 matters more than the library call.
From rules to money 🥭 4 min live
A validated rule feeds three classic actions. Cross-sell messaging: "bought sneakers? here are socks" - the email writes itself from the rule's two sides. Placement: put the pair together, on the shelf or on the product page. Bundles: price the pair as a set and let the lift do the persuading. For Mango Lane, the win-back email from session 7's segment sheet just got smarter: it can now feature what lapsed spenders' baskets historically paired.
LiveThe honest boundary: co-occurrence is not causation2 min▶
A rule describes what already happens in baskets; it does not explain why, and it does not promise that pushing A will drag C along. Sneakers and socks may pair because one causes the other, because both serve one outfit, or because both sit in a summer sale. The rule cannot tell you which - and does not need to, IF you treat it correctly: putting socks next to sneakers is a test of the rule, and the rule alone proves nothing. Ship the placement, measure attach rate against a control, and let the experiment - not the lift column - make the causal claim. A rule licenses a cheap test; it never licenses a causal sentence in a slide deck.
And the pointer this course owes you: rules are the shallow end of "people who bought X also...". Full recommender systems - collaborative filtering, matrix factorization, the personalized feed - live in learn-recommendation-with-phoebe on the Kirana case. This session stops at rules, on purpose: they are the interpretable, arguable, merchandiser-friendly member of the family.
Self-studyWhich action for which rule2 min▶
A rough matching, worth arguing with: cross-sell messaging wants high confidence on top of real lift, because every email costs attention and you want most recipients already inclined. Placement tolerates lower confidence - putting things near each other is nearly free, so any healthy-support rule with lift comfortably above 1 earns a shelf test. Bundles demand the most: real lift, thick support, AND a margin check the rule table knows nothing about, because a discount on a pair people already buy together is money handed back. In all three cases the rule nominates the candidate and the experiment confirms it - the table is a shortlist generator, never a decision.
Self-studyRules have a shelf life2 min▶
Session 7 said segments drift; rules drift harder, because baskets follow seasons, promotions, and stock. A pairing mined during a gifting season can evaporate by spring; a rule created by last month's bundle promotion is your own marketing echoing back at you, not customer preference. Two working habits follow. First, date every mined table and re-mine on a schedule, exactly like the segment sheet's review date. Second, before shipping any rule, ask what was happening in the shop during the mining window - a sale, a launch, a holiday - and whether the rule is the customers talking or the calendar. The arithmetic is timeless; the baskets are not.
Mine the baskets 🧺 ★ 20 min · live rule mining in your browser
The lab below mines association rules from 500 Mango Lane baskets the moment the page loads - real counting over real simulated receipts, computed live, no pre-baked table. The planted style pairs are in there; so are the popularity traps. Read the table the way part 2 taught you.
Know what you are looking at. The table was mined live from 500 baskets on page load - support, confidence, and lift counted for real in your browser, no script supplying answers. Reload the page and the counting runs again.
Read the top rule: white sneakers → crew socks. Support 14%, confidence 72%, lift 3.0x. Say the full sentence: the pair sits in 14% of all baskets, 72% of sneaker baskets also carry socks, and that is 3x more than sock-buying chance alone would predict. Buyers pair them - three times more than chance.
Find midi dress → leather belt (lift 2.9x). This is the second planted style pair, and it surfaced because the mining is real - nobody typed it into the page. The lab plants the pattern; the arithmetic finds it. That is the entire promise of the method, demonstrated.
Read a lower-lift row and say WHY it ranks lower. Pick any rule with decent confidence but modest lift and explain it out loud using part 2's trap: the consequent's base rate is doing the work, so the antecedent adds little pull. If you can articulate that, you can read any rule table in the industry.
Draft the cross-sell email the top rule writes for you. Subject line, one sentence, using both sides of the rule - something like "Your sneakers asked us for socks". Note how the rule hands you the WHAT (the pairing) while the segment sheet from session 7 hands you the WHO.
Run the lift-versus-confidence argument. Find any rule where confidence looks strong but lift sits near 1, and explain it via the popular-consequent trap: everyone buys that item anyway, so the rule earns no shelf move and no email. One strong-confidence row rejected out loud is the session's exit exam.
Homework 📝 ◐ 20 minutes
- Spot a cross-sell in the wild: find one "frequently bought together" or paired-placement in a real shop (physical or online) and reverse-engineer its rule - what is A, what is C, and would you bet its lift is above 2 or barely above 1?
- Hand-compute one rule: invent a small basket table (or reuse the toy: 100 baskets, A in 20, C in 25, both in 10) and compute support, confidence both directions, and lift on paper. The arithmetic must live in your hands, not the library's.
- Write when you would NOT ship a high-lift rule: three sentences covering the three vetoes - support too thin (spectacular ratio, three baskets), seasonal artifact (mined in December, shipped in March), and causation confusion (the rule licensed a placement test, someone's deck claimed the socks drive sneaker sales).
Three questions before you go 🎯 ◐ 90 seconds
1 · Support, confidence, and lift measure, in order...
Support = both ÷ all baskets. Confidence = both ÷ baskets with A (directional - flipping the rule changes the denominator). Lift = confidence ÷ C's base rate, centered on 1. Three questions, three denominators.
2 · A rule shows 70% confidence but lift almost exactly 1. What did you just learn?
Lift 1 means confidence merely equals the consequent's base rate - independence. The 70% was the item's own popularity reflected back at you. This is the popular-item trap, and lift is the column built to catch it.
3 · A high-lift, healthy-support rule licenses you to...
Rules describe co-occurrence, not causation - the pair may share a season, an outfit, or a sale. Putting socks next to sneakers TESTS the rule; only the experiment's result can support a causal sentence.
What this session covered from the official universe
Certificates, videos, and graded assessments stay with the official providers - this course teaches the working core with a live in-browser lab.