Market Basket Analysis in Data Mining
Every time a checkout scanner records what's in a shopping basket, it captures more than a receipt — it captures a small piece of evidence about which products tend to be bought together. Market Basket Analysis (MBA) is the data mining technique that turns thousands of these receipts into usable patterns: if customers who buy bread frequently also buy butter, a store can act on that by placing the two items near each other, bundling them into a combo offer, or simply making sure both are well stocked at the same time.
This became practical at scale once Point of Sale (POS) systems started recording every transaction digitally. Before that, purchase records existed mostly as handwritten receipts, far too labor-intensive to analyze in bulk for patterns across thousands of transactions. Digital transaction logs made it possible to search that same information automatically and reliably.
The Underlying Logic: Association Rules
Market Basket Analysis is an application of association rule mining, structured around a simple logical pattern: if a customer buys item A, they are more likely to also buy item B. This is written as a rule:
{Bread} → {Butter}
The item on the left, Bread, is the antecedent (the "if" part); the item on the right, Butter, is the consequent (the "then" part). A rule like this is only useful once it's backed by three specific numbers that quantify exactly how strong and reliable the pattern is — support, confidence, and lift.
The Three Core Measures, Computed on Real Transaction Data
Rather than plugging invented numbers into formulas, it's more instructive — and safer against arithmetic mistakes — to compute these measures directly on a simulated but realistic set of 414 shopping transactions, where bread-and-butter and pen-and-notebook were deliberately built to co-occur more often than chance, while milk and stapler were left to occur independently as a control.
Support: How Common Is the Combination?
Support measures how often an itemset appears across all transactions:
Support(A, B) = (transactions containing both A and B) / (total transactions)
support_bread = count_containing("bread") / total
support_butter = count_containing("butter") / total
print(support_bread, support_butter)
Output:
support(bread) = 0.406
support(butter) = 0.522
Support alone answers "how big a share of all transactions does this item, or this combination, represent?" — useful for judging whether a pattern is common enough to be worth acting on at all, but it says nothing yet about whether the two items are actually related.
Confidence: How Reliable Is the Rule?
Confidence measures, among transactions that already contain the antecedent, what fraction also contain the consequent:
Confidence(A → B) = (transactions containing both A and B) / (transactions containing A)
Note the direction carefully: confidence divides by the count of the antecedent alone, not by the count of both items together — dividing the other way around is a common mistake that can produce a "confidence" figure larger than 100%, which is a clear sign the formula was applied backwards. Computed directly on the data:
count_pen = count_containing("pen")
count_both = count_containing("pen", "notebook")
confidence = count_both / count_pen
print(count_both, "/", count_pen, "=", confidence)
Output:
68 / 110 = 0.618
Of the 110 transactions that included a pen, 68 also included a notebook — a 61.8% confidence that buying a pen predicts also buying a notebook in this data.
Lift: Is the Relationship Actually Meaningful?
Confidence alone can be misleading, because a high confidence can occur simply because the consequent item is popular on its own, with no real connection to the antecedent at all. Lift corrects for this by comparing the observed confidence to what would be expected if the two items were bought completely independently:
Lift(A → B) = Confidence(A → B) / Support(B)
Computed for all three pairs in the same dataset:
bread -> butter: confidence=0.673 support(butter)=0.522 lift = 0.673/0.522 = 1.289
pen -> notebook: confidence=0.618 support(notebook)=0.302 lift = 0.618/0.302 = 2.047
milk -> stapler: confidence=0.327 support(stapler)=0.326 lift = 0.327/0.326 = 1.003
This is what makes lift the measure that actually answers "is this relationship real?" A lift of 1.0 means the two items appear together exactly as often as pure chance would predict — precisely what shows up for milk and stapler, two items with no engineered relationship in this data at all, confirming the measure behaves exactly as expected on a genuinely unrelated pair. A lift above 1 means the items are positively associated — buying one genuinely raises the odds of buying the other — and pen-and-notebook's lift of 2.05 is a substantially stronger relationship than bread-and-butter's 1.29, even though bread-and-butter had the higher raw confidence (0.673 vs. 0.618). This is exactly why lift matters: confidence alone would have ranked bread-and-butter as the stronger pattern, but lift reveals that pen-and-notebook is actually the more meaningful association once each item's own popularity is accounted for. A lift below 1 would indicate a negative association — buying one item actually makes the other less likely, which can be just as useful to know as a positive one.
Types of Market Basket Analysis
Descriptive analysis looks only at past transaction data to find patterns that already exist, with no attempt to predict anything — establishing, for instance, that milk and biscuits are frequently bought together historically. Predictive analysis goes further, using a model built on past patterns to anticipate future behavior, which is what powers cross-selling — flagging that a customer who just bought a phone is statistically likely to buy a case or charger soon after. Differential analysis compares basket patterns across different conditions — time periods, store locations, or customer segments — to explain why buying patterns differ from one context to another, such as understanding why a product bundle sells well in one region but not another.
Algorithms Behind Market Basket Analysis
Finding every frequent itemset by checking every possible combination of items is computationally infeasible once a store carries thousands of distinct products — the number of possible combinations grows exponentially. The Apriori algorithm is the most widely used solution: it builds up frequent itemsets incrementally, starting from single items and only extending combinations that have already proven frequent at the previous size, which prunes away the vast majority of combinations that could never meet the support threshold anyway. Other algorithms such as AIS and SETM address the same underlying problem with different scanning and candidate-generation strategies, but Apriori's incremental, prune-as-you-go approach remains the standard starting point.
Where This Shows Up in Practice
- Retail — "frequently bought together" recommendations on e-commerce sites, and the physical placement of related items (shampoo next to conditioner) on store shelves.
- Telecom — bundling services, such as internet and TV packages, based on which combinations customers actually tend to subscribe to together.
- Banking and financial services — identifying which product offers (credit cards, insurance add-ons) tend to be adopted together, and using unusual combinations of transaction patterns as a signal in fraud detection.
- Healthcare — identifying which symptoms, conditions, or genetic markers tend to occur together, using the same underlying co-occurrence logic applied to clinical rather than retail data.
Why It's Worth Doing
The direct payoff is better decisions built on evidence rather than guesswork: which products to place near each other, which combinations to bundle into a promotion, which recommendation to surface next to a specific item, and where in a customer's typical purchase sequence a marketing message will land most effectively. All of it traces back to the same three numbers computed above — support to confirm a pattern is common enough to matter, confidence to measure how reliably it holds, and lift to confirm the pattern reflects a real relationship rather than the coincidental popularity of one item on its own.