Market Basket Analysis

Customer Analytics Association Rules

Find which products are bought together, and tell a real pattern from a coincidence, before you spend money on a bundle, a cross-sell prompt or an end-cap display.

🧭 Professor Mode: Guided Learning Experience

New to association rules? Professor Mode walks you through one store’s transactions end to end — including the two rules that look strongest on screen and should both be ignored.

OVERVIEW & WHAT THIS TOOL SOLVES

When you scan thousands of checkout receipts for cross-sell bundles or shelf adjacencies, sorting pairs by raw co-occurrence or conditional percentage ("70% of pasta buyers also bought bananas") falls straight into the Banana Trapβ€”recommending store-wide bestsellers that shoppers were going to buy anyway. Market Basket Analysis mines association rules (A β†’ B) and filters them by Support, Confidence, Lift, and multiple-testing significance to surface genuine product affinities.

🎯 Questions It Answers

  • Which product pairs or bundles co-occur in baskets significantly more often than store-wide chance would predict?
  • Which high-confidence rules are fake "banana rules" driven purely by a popular consequent item?
  • Which association rules survive minimum basket-count guards and false-discovery-rate (FDR) correction?

πŸ“‚ What Data You Need

  • Transaction Data: Basket/receipt ID paired with item names (long format, basket rows, or binary item matrix)
  • Rule Guards: Minimum co-occurrence basket count, minimum Confidence, and minimum Rule Lift thresholds
  • Focus Filter (Optional): Pin a focal item as antecedent (A β†’ ?) or consequent (? β†’ B)

πŸ’‘ What You'll Discover

  • Association Rule Table: Support, Confidence, Baseline rate, Rule Lift, Leverage, and exact p-values
  • Banana-Trap & Noise Diagnostics: Automatic flags for store-staple coincidence and tiny-sample flukes
  • Interactive Affinity Map: Support Γ— Confidence scatter colored by Lift and item-to-item network structure
πŸ” Key Nuances & Common Traps to Watch For

“Lift” here is not promotional lift

In promotions, lift means how much a campaign raised sales over baseline. Rule lift in Market Basket Analysis compares how often two items are bought together with how often they would land in the same basket by sheer coincidence (Confidence Γ· Baseline).

  • Why Confidence Flatters Popular Items: If 68% of all store baskets contain bananas, then "Pasta β†’ Bananas" at 70% confidence has a Lift of only 1.03Γ—β€”virtually random coincidence.
  • Why Lift Flatters Rare Niche Pairs: Two obscure items bought together in 5 out of 10,000 baskets can show a Lift of 40Γ—. Always enforce a minimum absolute basket count alongside Lift.
  • Co-Occurrence Is Not Causation: Finding that A and B are bought together tells you where to test a bundle or recommendation widget; proving incremental margin requires an A/B experiment.
πŸ“ Under the Hood: Model Equations & Variable Definitions

1. Support, Confidence & Rule Lift for Association Rule (A β†’ B)

\[ \text{Support}(A \to B) = \frac{N_{A \cap B}}{N}, \qquad \text{Confidence}(A \to B) = \frac{N_{A \cap B}}{N_A}, \qquad \text{Lift}(A \to B) = \frac{\text{Confidence}(A \to B)}{\text{Support}(B)} = \frac{P(A \cap B)}{P(A)\,P(B)} \]

πŸ’¬ Read it in plain English: Support measures how common the pair is across all baskets, Confidence measures how often B appears when A is in the basket, and Lift divides Confidence by B's store-wide popularity to show the multiple above random chance.

N
Total Baskets (Transactions)YOUR DATA β“˜
Total number of shopping baskets or receipts in the dataset.
NA, NB
Individual Item Basket CountsYOUR DATA β“˜
Number of baskets containing antecedent item A and consequent item B.
NA∩B
Co-Occurrence Basket CountYOUR DATA β“˜
Number of baskets containing both item A and item B together.
Support
Joint Basket PrevalenceOUTPUT β“˜
Proportion of all N baskets that contain both A and B: P(A ∩ B).
Confidence
Conditional Purchase RateOUTPUT β“˜
Proportion of A-baskets that also include B: P(B | A).
Lift
Co-Occurrence MultiplierINFERENCE β“˜
Ratio of observed co-occurrence to independent chance (> 1 positive affinity, = 1 coincidence).

2. Leverage & Conviction

\[ \text{Leverage}(A \to B) = P(A \cap B) - P(A)\,P(B), \qquad \text{Conviction}(A \to B) = \frac{1 - P(B)}{1 - \text{Confidence}(A \to B)} \]

πŸ’¬ Read it in plain English: Leverage measures the excess percentage of all baskets containing the pair above random chance, while Conviction measures how much less often the rule makes a mistake (A without B) compared to independence.

P(A), P(B)
Marginal Item ProbabilitiesESTIMATED β“˜
Store-wide baseline prevalence N_A/N and N_B/N for items A and B.
Leverage
Absolute Excess Co-OccurrenceOUTPUT β“˜
Difference between observed joint support and the support expected under independence.
Conviction
Directional Implications RatioINFERENCE β“˜
Ratio of expected error rate under independence to observed error rate when predicting B from A.

Step 1 CHOOSE YOUR DATA

Transaction data is the shape a till or a Shopify export already produces: one row per line item, with an order id repeated down the page. Start with a case study, or bring your own file.

📚

Use a Case Study

📤

Upload Your Data

Drag & Drop raw data file (.csv, .tsv, .txt)

Upload either a long transaction log (one row per line item with an order id and item name, plus optional customer id, date and segment) or a wide 0/1 basket matrix (one row per basket, 0/1 columns per product). Repeat lines for the same item in one order are counted once.

Clean or reshape in Import Wizard →

No file uploaded.

Step 2 SET THE GUARDS

Every setting here is a judgement about how much evidence you need before you are willing to call something a pattern. They are not formalities: the minimum count alone decides whether the rarest rules in your file are findings or noise.

A pair must appear in at least this many baskets before it can become a rule. 0.4% of baskets. This is a count rather than a percentage on purpose — a percentage hides how thin the evidence is.

Hides rules that happen no more often than coincidence. Filters the table only; every rule is still tested.

Hides rules below this hit rate. Raise it only after you have looked at lift.

Checks every rule against a false-discovery correction and hides the ones that do not survive. Leave this on unless you are deliberately exploring.

Hides “A and B → C” unless each of A and B makes C more likely than the other does alone, by its own test (with the same correction). Otherwise the pair is “A → C” with a passenger, not a second discovery.

Advanced: how big were the baskets?

A 50-item basket contains 1,225 different pairs. A 3-item basket contains 3. So large baskets manufacture co-occurrence all by themselves, and two products can look related simply because they both turn up in the weekly stock-up shop.

Lift cannot see this. It corrects for how common each item is, never for how much else was in the trolley at the same time. Switch this on to add a column comparing each rule’s typical basket with the store’s, and a rule running well above the store average is more likely to be co-presence than a cross-sell.

🤔 Try this

  1. Load Corner Market, untick Hide rules that could be chance, and click the Confidence heading to sort by it. Read the Expected column beside the rows ending in bananas.
  2. Now click Rule lift. The banana rows sink out of sight, because their lift is about 1. Tick the filter again.
  3. Drag the minimum baskets slider down to 5. A pair of expensive deli items appears near the top with an enormous lift.
  4. Open that rule and read its count. Would you reorganise a shelf on it?

The surprise worth sitting with: the first list, the second list and the third list rank the rules differently, and all three are correctly computed from the same data.

EXPLORATORY QUESTIONS

All answerable with the controls above. The last two are the ones worth arguing about in a meeting.

  1. Which rule has the highest confidence, and would you act on it? What does its expected column say?
  2. Which rule has the highest lift at the default minimum count? Now drop the minimum to 5. Does the answer change, and should it?
  3. Find a rule whose reverse direction has a very different confidence. What does that tell you about which item to put the prompt on?
  4. Load Deskline. Almost nothing survives. Is that a failure of the method, of the data, or a finding about the business?
  5. Search the table for beer and diapers. The famous story says they sell together. What does this dataset say, and what would you need to settle the question properly?
  6. You find a rule with a lift of 4 across 600 baskets. Your manager wants to move the two products next to each other. What is the one sentence you should say before they do?