Converter tool

Market Basket Analysis

Find which products are bought together. Load order lines or one basket per row, mine frequent itemsets with Apriori or FP-growth, and rank rules by support, confidence, lift, leverage and conviction. Runs in your browser.

Step 1

Load your transactions

Market Basket Analysis

Operator: Abdulla Al Fahad. How tools are built and checked

In the sample of 160 grocery orders, 30 of the 36 baskets with tomato sauce also hold pasta. That is the kind of rule market basket analysis finds: which products show up in the same order more often than chance would explain, ready to become a bundle, a shelf placement or a cross-sell prompt. You load an order export, set how common and how reliable a pattern must be, and read ranked rules with all five standard metrics.

Two things are worth knowing before you start. First, it finds associations, not causes: two items bought together may simply be popular, which is why lift and leverage are shown beside confidence. Second, it works on baskets, so you need to know which lines belong to the same order. If your data is customers over time rather than single orders, the RFM Segmentation tool answers a different question; this one is about what goes into the same basket.

Key features

  • Order-line or one-row-per-basket input, with comma, semicolon, pipe or tab separated items
  • Apriori and FP-growth, producing identical frequent itemsets of up to four items
  • Rules with support, confidence, lift, leverage and conviction, plus antecedent and consequent support
  • Sliders for minimum support, confidence and lift that update the rule list live
  • Sortable rules table with a filter to rules that mention one item
  • Item co-occurrence heatmap for the most frequent items, by lift, count or support
  • Itemsets table showing the most frequent single items and combinations
  • Export rules and itemsets to CSV, or all three tables to XLSX
  • Caps on items, itemsets and rules with clear messages, and a Cancel button for long runs

From order lines to rules: how baskets, itemsets and the five metrics are built

Two layouts are accepted. Order lines have one row per item with an order or basket id column and an item column, which is how most shop, POS and e-commerce exports look. Basket rows have one row per order with all the items in one cell, separated by a comma, semicolon, pipe or tab. The layout and columns are guessed from the table and can be changed. Files can be CSV, TSV or XLSX of up to 25 MB and 300,000 rows.

Cleaning is minimal and visible. Items are trimmed, repeats within one basket count once (two lines of the same product in one order is still one presence of that product), and case is ignored by default so Milk and milk are one item, with the first spelling shown. You can also drop single-item baskets, which cannot contain a pair but do count toward the basket total; removing them raises every support value, because the denominator shrinks.

The thresholds are minimum support, the share of all baskets that must contain the itemset; minimum confidence, the share of baskets with the antecedent that also contain the consequent; and minimum lift, with 1 meaning no association. The largest itemset size can be 2, 3 or 4; a size of 3 allows rules with two items on the left. Both Apriori and FP-growth are offered and return identical itemsets, FP-growth being usually faster at low support.

To keep the page fast the mining is capped. Only the 400 most frequent items are kept (the summary says when this cuts items), at most 100,000 frequent itemsets are generated and at most 5,000 rules are listed, strongest lift first. The work runs in slices so the browser stays responsive, and a Cancel button stops it. When a cap bites, a message says which one and by how much.

How it works

The tool turns each basket into a set of item ids ranked by frequency, then finds every itemset whose count reaches the support threshold. Apriori builds candidates level by level: frequent single items are paired, the pairs that reach the threshold are extended to triples whose every sub-pair is already frequent, and so on to the chosen size. FP-growth compresses the baskets into a prefix tree of items ordered by frequency and mines conditional trees from it, avoiding the candidate generation. The two were cross-checked on random data and always agree.

Every frequent itemset of two or more items is split into all possible antecedent and consequent pairs. For a rule A to B with n baskets, support is count(A and B) over n, confidence is count(A and B) over count(A), lift is confidence over the support of B, leverage is support(A and B) minus support(A) times support(B), and conviction is (1 minus support(B)) over (1 minus confidence), shown as inf when confidence is 1. Lift above 1 means the items appear together more than independence predicts; leverage gives the same signal as a share of all baskets; conviction measures how much more often the rule would be wrong if A and B were independent.

A hand-checkable case is the textbook five-basket example: bread and milk; bread, diapers, beer and eggs; milk, diapers, beer and cola; bread, milk, diapers and beer; bread, milk, diapers and cola. Diapers and beer appear together in 3 of 5 baskets, so support is 0.6. Diapers appear in 4 baskets, so confidence of diapers to beer is 0.75; beer appears in 3, so lift is 0.75 over 0.6, which is 1.25; leverage is 0.6 minus 0.8 times 0.6, or 0.12; conviction is 0.4 over 0.25, or 1.6. Beer to diapers has confidence 1 and conviction inf.

Common use cases

  • Choosing bundle offers for an online shop from a Shopify or WooCommerce order export
  • Planning shelf adjacency or an end-cap in a small grocery or convenience store
  • Building a customers also bought block that is backed by actual order data instead of a guess
  • Finding accessories that accompany a main product in a hardware or electronics catalogue
  • Checking which menu items are ordered together in a cafe to design a combo

How to use this tool

  1. Upload the order export, or click Load example for 160 sample grocery orders, and confirm the layout and the id and item columns.
  2. Start with a minimum support low enough to keep your rarer products, about 1 to 2 percent for a few thousand baskets, and a lift of 1.2 or more.
  3. Raise the confidence and lift sliders until the list is short enough to read, and sort by lift or confidence.
  4. Download the rules and itemsets for merchandising, or filter by an item first to export only what concerns it.

Example

160 synthetic grocery orders in long format (order_id, product), 14 products; support 3%, size 2, confidence 40%, lift 1.5

order_id,product
A1001,Bread
A1001,Milk
A1002,Pasta
A1002,Tomato sauce
... (about 500 order lines)

Strongest rules, 11 pass the filters

Salsa -> Tortilla chips   12 baskets, support 7.5%, confidence 66.7%, lift 5.93, leverage 0.062, conviction 2.66
Tomato sauce -> Pasta     30 baskets, support 18.8%, confidence 83.3%, lift 3.17, leverage 0.128, conviction 4.43
Pasta -> Tomato sauce     same 30 baskets, confidence 71.4%, lift 3.17, conviction 2.71
Butter -> Bread           25 baskets, confidence 71.4%, lift 2.24; Bread -> Butter confidence 49.0%
Item counts: Milk 76, Bananas 54, Bread 51, Eggs 46, Pasta 42, Tomato sauce 36

Tips for best results

  • Read lift before confidence. In the example Bread to Butter has a confidence of 49 percent, which sounds strong, but lift of 2.24 is what shows butter is bought more with bread than its 22 percent overall popularity would suggest.
  • Watch asymmetry. Tomato sauce to Pasta has confidence 83.3 percent while Pasta to Tomato sauce has 71.4 percent: nearly every sauce buyer also buys pasta, but not every pasta buyer buys sauce, so the sauce is the better item to promote at the pasta aisle.
  • Set minimum support from the count, not the percentage. The hint under the slider shows how many baskets that is; a rule resting on four orders is anecdote at any percentage.
  • Use leverage to rank rules for business impact. A rare pair can have huge lift and tiny leverage (Salsa and Tortilla chips: 0.062), while a common pair with modest lift moves more baskets.
  • Filter to one item when you are deciding what to bundle with a specific product, instead of reading the whole table.

Common pitfalls

A very popular item appears in many rules with lift near 1. Milk is in nearly half the baskets, so rules ending in milk have high confidence and low lift. High confidence alone mostly reflects popularity.

Support thresholds that are too low produce a flood of coincidences. With 14 products and 160 baskets there are only a few dozen real patterns; with 400 items and 10,000 baskets, a 0.1 percent threshold will return thousands of rules, most of them noise.

Dropping single-item baskets changes every support value. Decide on it before comparing against a report built another way.

The item cap of 400 hides rare products. If your catalogue has 3,000 SKUs, group them into categories first, or you will only learn about the best sellers.

Order lines that share an id but belong to different customers (a reused cart id) create baskets that never existed. Check that the id really is per order.

Common errors and how to fix them

"No baskets could be built with these columns"
The id and item columns are probably the wrong way round, or a one-row-per-basket file was read as order lines. Switch the layout and check the delimiter.
"The search stopped at 100,000 itemsets"
Raise the minimum support or lower the largest itemset size. The cap keeps the browser responsive, and the list shown is incomplete while the message is on.
"At this support an itemset can qualify from a single basket" or no rules at all
Raise minimum support before trusting anything shown. If no rules appear, lower minimum lift to 1 and confidence to about 20 percent until the itemsets table shows pairs.

Best practices

  • Validate any rule you plan to act on with a small experiment, such as a bundle offer on half the traffic, before rolling it out.

Reading a heatmap of pairs

The heatmap shows the most frequent items on both axes, with each cell coloured by how strongly the two co-occur. Switch the cell value between lift, raw count and support. Counts favour popular items, so Milk, Bananas and Bread light up first; lift removes that popularity and shows the surprising pairs instead, such as the Salsa and Tortilla chips cell at 5.93.

A good use is to scan the lift view for bright cells between items that sit in different categories. Those are the cross-category affinities that are hardest to guess and easiest to monetise, and each one has a rule in the table with its exact numbers.

Frequently asked questions

What is a good lift value?

Above 1 means the items are bought together more than chance predicts. In practice values of 1.2 to 1.5 are weak signals, 2 and more are clear, and the 3 to 6 range usually reflects deliberate product pairings such as sauce with pasta.

Why is conviction shown as inf for some rules?

When confidence is exactly 1, every basket with the antecedent also holds the consequent, so the rule is never wrong in this data and conviction is unbounded. It happens often with rare consequents or small samples.

Can it handle quantities or prices?

No. It looks only at which items appear in a basket, once each. Quantities, revenue and time are ignored, so a rule says the items go together, not how much money they make.