Market Basket Analysis: Method Guide
Updated October 2026
Executive Summary
Market basket analysis finds items that tend to appear together in the same transaction. The idea is simple, but turning a pile of transaction records into rules you can act on takes care: the data has to be prepared properly, the thresholds have to be chosen with a purpose, and the output has to be read with the right metric in mind.
To see which of your own items sell together, try the free market basket tool.
This paper is an explanation of the method, not a study. It reports no original data, no customer results and no benchmarks. It defines support, confidence and lift, describes how the Apriori and FP-Growth algorithms find frequent itemsets, offers guidance on preparing data and choosing thresholds, lists common pitfalls, and works through one small example whose numbers are made up for illustration.
Key Points
- Three metrics, three questions: support says how common an itemset is, confidence says how often the consequent appears when the antecedent does, and lift says whether the pair appears together more often than chance would predict.
- Lift guards against popularity: a rule can have high confidence only because its consequent is bought in most baskets. Lift divides that popularity out.
- Thresholds set the size of the output: a lower minimum support produces many more itemsets and more computation, so thresholds are a trade-off between completeness and manageability.
- Preparation comes first: duplicate rows, returns and test records change the counts that every metric is built from.
- A rule is a pattern, not a cause: association rules describe co-occurrence in past data. Whether acting on one helps is a separate question, best answered with a controlled comparison.
1. Introduction and Scope
1.1 What Market Basket Analysis Does
Market basket analysis asks which items are purchased together. The canonical illustration, an association between beer and diapers, is retold so often in data science folklore that its origin is hard to trace; treat it as a story about the kind of question being asked, not as evidence of anything. The practical question is always the same: given a set of transactions, which combinations of items occur together often enough, and more often than chance, to be worth attention?
The technique applies wherever records group items into sets: retail baskets, online orders, restaurant tickets, or any other list of things that happened together. The output is a set of association rules of the form "if A, then B", each with metrics that describe how strong the pattern is.
1.2 Why It Is Easy to Misuse
The number of possible item combinations grows very quickly with the size of the catalog, so algorithms rely on thresholds to limit what they report. Poorly chosen thresholds either bury the reader in thousands of obvious rules or hide the few interesting ones. Separately, the metrics are easy to misread: a rule with high confidence may simply reflect a very popular item, and a rule with high lift may rest on only a handful of baskets.
1.3 Scope of This Paper
This paper covers the method only: the definitions, the algorithms, data preparation, threshold selection, interpretation and common mistakes. It does not report results from any dataset, and it makes no claim about how much revenue or conversion any approach produces. Where it gives numeric ranges, they are conventional starting points to adjust, not findings. The one numeric example, in Section 5, uses made-up numbers and is labelled that way.
2. Background
2.1 Association Rule Mining
Market basket analysis rests on association rule mining, formalised in the early 1990s. The Apriori algorithm, introduced by Agrawal and Srikant, established the standard approach for finding frequent itemsets in transaction databases. It uses the principle that if an itemset is frequent, all of its subsets must also be frequent, which lets it prune the search space through level-wise exploration.
Later algorithms addressed computational cost. FP-Growth avoids candidate generation by compressing the transactions into a compact FP-tree and extracting patterns through recursive traversal. ECLAT uses a depth-first search over sets of transaction identifiers and is often discussed for datasets with long transactions.
2.2 Where the Technique Is Used
The same idea is applied in several domains: "frequently bought together" features in online stores, store layout and promotion planning in retail, cross-sell analysis for financial products, and co-occurrence analysis of items in other record sets. The mathematics is identical in each case; what changes is what counts as a transaction and what counts as an item.
2.3 Known Limitations of the Method
Standard association metrics describe frequency, not value. They do not measure revenue, margin or customer lifetime value. High-support rules tend to involve popular items that already sell well. Low-support rules may point to niche pairings but fail minimum thresholds in aggregate data. Treating all transactions alike can also hide differences between customer groups, and a rule computed on a historical snapshot may not reflect current behaviour. These are properties of the method, and the guidance below is aimed at working around them.
3. Methodology: How the Method Works
3.1 The Input: Transactions and Items
The input is a list of transactions, each containing a set of items. Quantities and order are ignored by the basic method; only presence in the basket matters. Because most items appear in only a small share of transactions, the item-by-transaction matrix is sparse, and the algorithms are designed with that in mind.
3.2 Support, Confidence and Lift
For a rule A → B, where A and B are itemsets, the three standard metrics are:
- Support of an itemset is the fraction of transactions that contain it. Support(A ∪ B) = (transactions containing both A and B) / (all transactions).
- Confidence of A → B is the fraction of transactions containing A that also contain B. Confidence = Support(A ∪ B) / Support(A). It is the conditional probability of B given A.
- Lift of A → B is Confidence / Support(B), equivalently Support(A ∪ B) / (Support(A) × Support(B)). A lift of 1 means A and B appear together exactly as often as independence would predict. Above 1 indicates a positive association, and below 1 indicates the items appear together less often than chance.
Confidence alone is misleading when B is very common, because B will follow almost anything. Lift corrects for this by comparing against the base rate of B. Support matters because a rule built on very few baskets is unreliable whatever its lift.
3.3 The Apriori Algorithm
Apriori works level by level. It first counts single items and keeps those meeting the minimum support. It then builds candidate pairs only from the surviving items, counts them, and keeps the frequent pairs. It continues to triples and larger itemsets, each time generating candidates only from the frequent itemsets of the previous size. Because any subset of a frequent itemset must itself be frequent, large parts of the search space are never examined. Once frequent itemsets are found, rules are formed by splitting each itemset into an antecedent and a consequent and keeping those that meet the confidence (and optionally lift) threshold.
3.4 The FP-Growth Algorithm
FP-Growth works in two phases. First it scans the data to find frequent items and builds an FP-tree, a prefix tree in which transactions that share leading items share a path, so the data is stored compactly. Second, it mines the tree recursively, extracting frequent itemsets from conditional sub-trees without generating candidate lists. It typically needs fewer passes over the data than Apriori and is a common choice for large item catalogs. Both algorithms return the same frequent itemsets for the same thresholds; they differ in how they get there.
3.5 Data Preparation
Every metric is a ratio of counts, so anything that distorts the counts distorts the rules. Common preparation steps are:
- Remove records missing key fields such as transaction identifier or item code.
- Consolidate duplicates. The same transaction appearing twice inflates support for its items.
- Decide how to treat returns. Either remove them or analyse them as a separate stream; do not let them silently count as purchases.
- Exclude test and migration records, and review unusually large baskets such as bulk or wholesale orders that do not reflect ordinary shopping.
- Choose the item level. Merging variants (sizes, colours) or rolling items up to categories reduces sparsity and raises support, at the cost of specificity. A common approach is to explore at category level and then drill into item level for promising categories.
4. Key Points
Point 1: Choosing Thresholds Is a Trade-off
Minimum support controls how many itemsets the algorithm must consider. Lowering it admits rarer combinations but increases the number of candidates and the computation, sometimes dramatically in large catalogs. Raising it keeps results fast and statistically steadier but excludes niche pairings. Minimum confidence and minimum lift then filter the rules built from those itemsets.
There is no universal correct setting. A reasonable procedure is:
- Start conservative. Pick a support level high enough that the run finishes quickly and produces a short list. Small percentages of all transactions are a common starting point; adjust to your data.
- Read a sample of the rules. Look at a few dozen and ask which would change a decision you actually make.
- Adjust. If most sampled rules are obvious or unusable, tighten the thresholds. If almost none appear, loosen them.
- Repeat until the list is short enough for a person to review and still contains useful surprises.
As a rule of thumb, require a lift clearly above 1 before taking a rule seriously, and also require enough supporting baskets that the rule is not an accident of a few transactions. What counts as "clearly above" and "enough" depends on the data and the decision.
Point 2: Segment When Groups Behave Differently
Pooling every transaction produces averaged patterns. If different customer groups, channels or stores buy differently, a rule that holds in one group can be diluted, or even hidden below the support threshold, in the pooled data. Running the analysis separately per segment (for example by store, channel, or customer lifecycle stage) is worth considering when there is a reason to expect different behaviour and each segment has enough baskets to support stable counts. Segmentation multiplies the number of models to maintain, so it should be adopted where it answers a real question.
Point 3: Patterns Change Over Time
Seasons, promotions, product launches and changing preferences all shift what is bought together. Ways to account for this include analysing rolling time windows and comparing the rules across windows, splitting by season or day of week, and weighting recent transactions more heavily. Rules that persist across windows are better candidates for lasting use than rules that appear in one window only. Rules tied to a promotion or a season should be treated as conditional on it.
Point 4: Common Pitfalls
- Reading confidence without lift. A rule pointing at a very popular item looks strong on confidence even when the items are unrelated.
- Ignoring support. A high-lift rule seen in a handful of baskets may reflect sampling noise and needs more supporting baskets before anyone acts on it.
- Mistaking the obvious for the useful. Rules that reflect an existing bundle, a promotion or a product that cannot be bought without another add nothing new.
- Reading association as causation. Co-occurrence does not show that recommending B to a buyer of A will increase sales.
- Unreviewed output. Thousands of rules that nobody reads do not inform any decision. Rank and filter before presenting.
- Privacy. Purchase histories linked to individuals can reveal sensitive attributes. Prefer aggregate analysis where the question allows, and apply the protections appropriate to your catalog and jurisdiction.
Point 5: Checking Whether a Rule Is Worth Acting On
Statistical checks and business judgement serve different purposes, and both help. Hold out part of the data, or use a later time period, and see whether rules found in the earlier portion still appear. Have someone who knows the products review the rules and discard spurious or already-known ones. If a rule is used to drive recommendations or promotions, compare outcomes against a control group that does not receive them, since the rule itself says nothing about the effect of acting on it.
5. Worked Example (Illustrative)
Illustrative example with made-up numbers. These figures are invented to show the arithmetic. They do not come from any real dataset.
Suppose a shop has 100 baskets. Suppose 40 contain bread, 25 contain butter, and 20 contain both. Suppose 60 contain milk, 30 contain eggs, and 18 contain both milk and eggs.
| Rule | Support | Confidence | Lift |
|---|---|---|---|
| bread → butter | 20 / 100 = 0.20 | 20 / 40 = 0.50 | 0.50 / 0.25 = 2.0 |
| butter → bread | 20 / 100 = 0.20 | 20 / 25 = 0.80 | 0.80 / 0.40 = 2.0 |
| milk → eggs | 18 / 100 = 0.18 | 18 / 60 = 0.30 | 0.30 / 0.30 = 1.0 |
Reading the table in this made-up scenario: bread and butter appear together in a fifth of baskets, and a basket with bread contains butter half the time, which is twice as often as the 25 percent base rate for butter, so lift is 2.0. The reverse rule has the same support and the same lift but a higher confidence, because butter is the rarer item. Milk and eggs appear together in 18 baskets, but that is exactly what independence predicts (0.60 × 0.30 = 0.18), so lift is 1.0 and the rule carries no information beyond the popularity of the two items, even though its support is nearly as high as the bread and butter rule.
The example shows why lift is read alongside support and confidence, and why a rule's direction matters. It says nothing about what real shoppers do.
6. Practical Guidance
The steps below are a suggested order of work, not a measured or proven process. Adapt them to your data and to the decision the analysis is meant to inform.
A Suggested Workflow
- Define the question and the decision. Which choice will the rules inform: a recommendation widget, a shelf layout, a promotion? That determines what counts as a useful rule.
- Prepare the data as described in Section 3.5, and settle the item level.
- Explore with conservative thresholds and read a sample of the output.
- Calibrate thresholds using the procedure in Point 1, and consider segments and time windows if the question calls for them.
- Review the rules with someone who knows the products, and remove the obvious and the spurious.
- Act on a small number of rules and compare against a control before scaling up.
- Refresh periodically, since the patterns will drift.
Scale
Small catalogs and modest transaction counts are handled easily by standard libraries. Very large catalogs make low support thresholds expensive, since memory and time grow with the number of frequent itemsets. FP-Growth is generally preferred over Apriori at that scale, and raising the support threshold, rolling items up to categories, or sampling for initial exploration are the usual ways to keep a run tractable.
7. Conclusion
Market basket analysis is a well-established method for describing which items occur together. Its core is small: three metrics (support, confidence and lift) and two main algorithms (Apriori and FP-Growth) that find frequent itemsets under a support threshold. Most of the practical difficulty lies around the algorithm rather than in it: preparing the counts so they mean what they appear to mean, choosing thresholds that yield a reviewable list, reading lift and support alongside confidence, and remembering that a rule describes the past data and does not by itself predict the effect of acting on it.
This paper has explained those pieces and illustrated the arithmetic with an invented example. It makes no claim about results on real data. If you have transaction data of your own, the free tool linked at the top of this page runs the analysis on a CSV so you can see the rules your own baskets produce.
References and Further Reading
Academic Literature
- Agrawal, R., & Srikant, R. (1994). Fast algorithms for mining association rules. Proceedings of the 20th International Conference on Very Large Data Bases, 487-499.
- Han, J., Pei, J., & Yin, Y. (2000). Mining frequent patterns without candidate generation. ACM SIGMOD Record, 29(2), 1-12.
- Zaki, M. J. (2000). Scalable algorithms for association mining. IEEE Transactions on Knowledge and Data Engineering, 12(3), 372-390.
- Kaur, M., & Kang, S. (2016). Market basket analysis: Identify the changing trends of market data using association rule mining. Procedia Computer Science, 85, 78-85.
- Chen, M. C., Chiu, A. L., & Chang, H. H. (2005). Mining changes in customer behavior in retail marketing. Expert Systems with Applications, 28(4), 773-781.
Technical Resources
- MLxtend Python Library Documentation: Association Rule Mining Implementation
- Apache Spark MLlib: FP-Growth for Large-Scale Market Basket Analysis
- R arules Package: Mining Association Rules and Frequent Itemsets
Your turn
Bring your own data and the question you actually need answered.
MCP AnalyticsData science by email Send us your data and your question, and we will reply. ds@mcpanalytics.ai
Frequently Asked Questions
How many transactions do I need for market basket analysis?
There is no fixed minimum. What matters is how many baskets support each rule you intend to use. A rule built on a handful of baskets is unreliable whatever its lift, so check the absolute number of supporting transactions as well as the percentage. Sparse data and large catalogs need more transactions than small, dense ones.
How do you choose support and confidence thresholds for association rules?
Treat thresholds as settings to tune, not constants. Start conservative, read a sample of the resulting rules, and loosen or tighten until the list is short enough to review and still contains rules that would change a decision. Lower support admits rarer combinations at higher computational cost; higher confidence keeps only rules that hold more often but may miss emerging patterns. Use lift to filter: a value of 1 means no association beyond chance, and you choose how far above 1 a rule must be to matter for your purpose.
What are the computational considerations for large transaction sets?
The number of candidate itemsets grows quickly as the support threshold falls and as the catalog grows. Apriori generates candidates level by level and can become slow; FP-Growth avoids candidate generation and is usually preferred for large catalogs. Common ways to keep runs manageable include raising minimum support, rolling items up to categories, and exploring on a sample first. Memory use grows with the number of frequent itemsets, so threshold choice is also a resource decision.
How should time be handled in market basket analysis?
Shopping patterns shift with seasons, promotions and product lifecycles. Options include analysing rolling time windows and comparing the rules between them, splitting transactions by season or day of week, and weighting recent transactions more heavily. Sequential pattern mining is a related method that also records the order of purchases across visits.
How can you check that a rule is worth acting on?
Use several checks together. Hold out later data or a time-based split and see whether the rule still appears. Have someone who knows the products review the rules and discard spurious or already-known ones. If the rule will drive recommendations or promotions, compare results against a control group, because the rule describes past co-occurrence and does not by itself show what happens when you act on it.