What Is Market Basket Analysis? Metrics, Examples, and Use Cases

Market basket analysis is a method for finding which products are bought together in the same transaction. It scans order data for item combinations that appear more often than chance would predict. Three metrics describe each pattern: support, confidence, and lift. Retailers and online stores use it for cross-selling, bundles, and product placement.
This guide explains how the method works, how to calculate each metric, and how to read the results. It also covers the common algorithms, the main use cases, and the limits worth knowing before you act on a rule.
What market basket analysis is
The basic idea behind market basket analysis is simple. Every order is a basket of items. Across thousands of baskets, some items keep showing up together. The analysis finds those combinations and measures how strong each one is.
The output is a set of association rules. A rule reads "if a basket contains A, it is also likely to contain C." A is called the antecedent, and C is the consequent. Both can be single items or groups of items.
The documentation for mlxtend, a widely used Python library for this work, gives the classic illustration. It describes a rule suggesting "that people who buy diapers are also likely to buy beer." Whether or not that pairing holds in a given store, it shows the shape of the output.
The technique belongs to a broader field called association rule learning. The mlxtend docs note that the Apriori algorithm "has been designed to operate on databases containing transactions, such as purchases by customers of a store." Retail is where the method started, but any data made of baskets works.
How it works
A market basket analysis runs in two stages.
Stage one finds frequent itemsets. An itemset is any group of items, such as {phone case, screen protector}. It counts as frequent when it appears in at least a minimum share of all transactions. You set that minimum, called the support threshold.
Stage two turns itemsets into rules. For each frequent itemset, the algorithm splits it into an antecedent and a consequent and scores the resulting rule. The mlxtend docs describe rule generation as "a common task in the mining of frequent patterns."
The input is always the same shape. Each row is a transaction, and each column marks whether an item was in it. Order exports from most e-commerce platforms can be reshaped into this format with a pivot.
Three preparation choices shape the result before any metric is computed. First, decide what a transaction is, which is usually one order ID. Second, record presence rather than quantity, so three units of one item still count once. Third, choose the level of detail. Product categories give fewer, broader rules, while individual SKUs give more precise rules that need more data.
The three core metrics
Every rule gets three numbers. Reading them together is what separates a useful rule from a coincidence.
Support
Support is the share of all transactions that contain the itemset. If 60 of 1,000 orders contain both a phone case and a screen protector, the support of that pair is 0.06, or 6%.
Support tells you how common a pattern is. A rule with very low support may be real but too rare to act on.
Confidence
Confidence is the probability of seeing the consequent, given that the basket already contains the antecedent. It equals the support of the pair divided by the support of the antecedent.
Confidence has a direction. The confidence of A leading to C is usually different from C leading to A. The worked example below shows why.
Lift
Lift compares the pair's actual frequency with what you would expect if the two items were unrelated. It equals the confidence of the rule divided by the support of the consequent.
The mlxtend docs describe the reference point clearly: "If A and C are independent, the Lift score will be exactly 1." A lift above 1 means the items appear together more often than chance. A lift below 1 means they appear together less often.
A worked example
Take an online electronics store with 1,000 orders in a month.
| Measure | Value |
|---|---|
| Orders containing a phone case | 200 |
| Orders containing a screen protector | 100 |
| Orders containing both | 60 |
| Support of the pair | 60 / 1,000 = 0.06 |
| Confidence, phone case to screen protector | 0.06 / 0.20 = 0.30 |
| Confidence, screen protector to phone case | 0.06 / 0.10 = 0.60 |
| Lift | 0.30 / 0.10 = 3.0 |
Read the results in plain terms. Three in ten phone case buyers also bought a screen protector. Six in ten screen protector buyers also bought a phone case. The pair appears together three times as often as chance would predict.
When the full rule table comes back, read it in a fixed order. Sort by lift to find the strongest links. Drop rules below your minimum support, because they are too rare to act on. Then use confidence to decide which direction to recommend in.
The two confidence figures lead to different actions. Suggesting a phone case to screen protector buyers is the stronger recommendation, because 60% of them already take one. The lift is the same in both directions, which is why lift is the better measure of the strength of the link itself.
Other metrics worth knowing
The three core metrics cover most needs, but libraries report others that help filter weak rules.
Leverage measures the gap between observed and expected co-occurrence. The mlxtend docs define it by comparing observed co-occurrence with "the frequency that would be expected if A and C were independent." A leverage of 0 means independence.
Conviction measures how strongly the consequent depends on the antecedent. Like lift, a value of 1 indicates independence. Higher values mean the rule is violated less often than chance would suggest.
In practice, most teams sort rules by lift, then filter by a minimum support and confidence. That combination surfaces patterns that are strong, common enough to matter, and reliable.
Algorithms: Apriori and FP-Growth
Apriori is the classic algorithm. The mlxtend documentation cites Agrawal and Srikant's 1994 paper on fast algorithms for mining association rules as its source. Apriori builds itemsets level by level and prunes any itemset whose subsets are not frequent, which keeps the search manageable.
FP-Growth reaches the same frequent itemsets by a different route. The mlxtend docs describe it as "a popular alternative to the established Apriori algorithm." It builds a frequent pattern tree and does not require candidate generation. The docs say this makes it "particularly attractive for large datasets."
The support threshold works the same way in both. The mlxtend docs give a simple example: at a threshold of 0.5, a frequent itemset must appear in at least half of all transactions. Retail thresholds are usually far lower, because even popular pairs appear in a small share of orders.
For most business questions, the choice of algorithm changes speed, not results. Both return the same itemsets for the same support threshold.
What market basket analysis is used for
Market basket analysis is most common in retail and e-commerce, but the use cases extend further.
- Cross-selling. Recommend the consequent at checkout when the antecedent is in the cart.
- Bundles. Package items with high lift into a single offer.
- Store and page layout. Place frequently paired items near each other, on a shelf or on a product page.
- Inventory planning. Stock paired items together, so a shortage of one does not quietly suppress sales of the other.
- Content and media. Treat a user session as a basket and find which articles or videos are consumed together.
- Services. In banking or telecom, treat each customer's products as a basket and find which combinations tend to go together.
- Campaign review. Compare lift for a pair before and during a campaign. A jump shows the campaign changed buying behavior, not just volume.
Each use case starts from the same question. When customers choose one thing, what else do they tend to choose?
The action that follows should match the confidence direction. A bundle works when both items are wanted together. A checkout suggestion works when one item reliably leads to the other.
Market basket analysis vs related methods
Market basket analysis is often confused with customer segmentation and with recommendation engines. The table shows how they differ.
| Method | Unit of analysis | Main question | Typical output |
|---|---|---|---|
| Market basket analysis | Transactions | Which items go together? | Association rules with support, confidence, and lift |
| Customer segmentation | Customers | Which customers are alike? | Groups of customers with shared traits |
| Collaborative filtering | Customer and item history | What will this person like next? | Personalized recommendations |
| Cohort analysis | Groups by start date | How does behavior change over time? | Retention curves and tables |
The methods complement each other. Segmentation can tell you who your high-value customers are, and market basket analysis can tell you what those customers buy together. Our guide to building a customer segmentation report covers the first half, and our explainer on cohort analysis covers the time dimension.
Limits worth knowing
The rules from market basket analysis are useful, but they are easy to over-read.
Co-occurrence is not causation. A high-lift pair tells you two items are bought together. It does not tell you that buying one causes the other.
Thresholds shape the answer. Set support too high and you miss niche but valuable pairs. Set it too low and you get thousands of rules, many of them noise.
Rare items get lost. An expensive item bought a few times a month may never reach the support threshold, even if its pairings are strong.
Returns and cancellations distort baskets. If returned items stay in the data, the analysis counts pairings that customers reversed. Our guide to a product returns report covers how to measure that side separately.
Many pairs mean some false patterns. A catalog of 500 items has more than 100,000 possible pairs. Some will show high lift by chance alone. Confirm important rules on a second period of data before acting on them.
Time matters. Patterns during a holiday season may not hold in spring. Run the analysis on comparable periods before you change a layout or a bundle.
How to run one without writing code
The classic route is Python, with a library such as mlxtend, or SQL for counting pairs. Both require reshaping the order data into one row per transaction and one column per item.
A spreadsheet can handle a small version. A pivot table counts orders per item, and a COUNTIFS formula counts orders containing both items in a pair. The limit is scale, because the number of possible pairs grows quickly with the catalog.
An AI workspace can do the reshaping and counting from a plain order export. Powerdrill Bloom lists uploads of Excel and CSV on every plan. You can ask which products are most often bought together and request support, confidence, and lift for the top pairs.
Start with a category-level run to see the broad patterns. Then rerun at SKU level for the categories that matter most.
Check the output the same way you would check a script. Confirm the transaction count, spot-check one pair by hand, and make sure returned orders were excluded. The CSV AI assistant page shows the file-first workflow.
If you have an order export ready, you can try Powerdrill Bloom on it and compare the top pairs with what your team expects.
Frequently asked questions
What is market basket analysis in simple words?
It is a way of finding which products customers tend to buy together. It looks at many orders and measures how often each combination appears, compared with what chance would predict.
What is lift in market basket analysis?
Lift compares how often two items appear together with how often they would appear if they were unrelated. A lift of 1 means no association. Above 1 means they appear together more than expected, and below 1 means less.
How do you calculate support and confidence?
Support is the number of transactions containing the itemset divided by all transactions. Confidence is the support of the pair divided by the support of the antecedent. Both are usually shown as decimals or percentages.
Which algorithm is used for market basket analysis?
Apriori is the classic algorithm, and FP-Growth is a common faster alternative. Both find frequent itemsets from transaction data, and rules are then generated and scored from those itemsets.
Can you do market basket analysis in Excel?
Yes, for small datasets. A pivot table counts orders per item, and COUNTIFS counts orders containing a pair. For large catalogs, the number of pairs grows quickly, so a script or an AI tool is more practical.
Sources: mlxtend, Association rules · mlxtend, Apriori. The worked example uses illustrative figures.