Market basket analysis looks for items that tend to be bought together. The three measures behind it, support, confidence and lift, look abstract until you compute them once on a table small enough to check by eye. So here are ten invoices from an imaginary kirana store.

  1. Bread, butter, milk
  2. Bread, butter
  3. Bread, jam
  4. Milk, tea
  5. Bread, butter, tea
  6. Milk, biscuits
  7. Bread, butter, jam
  8. Tea, biscuits
  9. Bread, milk
  10. Butter, milk

Count how often each item appears: bread in 6 invoices, butter in 5, milk in 5, tea in 3, biscuits in 2, jam in 2.

Support: how common is the combination?

Support is the share of all invoices that contain the items. Bread and butter appear together in invoices 1, 2, 5 and 7, so 4 of 10, a support of 0.40. Bread and milk appear in invoices 1 and 9, a support of 0.20. Tea and biscuits appear together only in invoice 8, a support of 0.10.

Support is a filter for credibility. A pairing seen once in ten invoices may be a coincidence; in a real dataset of lakhs of invoices you would set a minimum, perhaps a fraction of a percent, and discard anything rarer.

Confidence: if they buy A, how often do they also buy B?

The confidence of “bread then butter” is the support of the pair divided by the support of bread: 4 of the 6 bread invoices also contain butter, or 67 percent. The reverse, “butter then bread”, is 4 of 5, or 80 percent. Confidence is directional, so the two rules differ, which matters when you decide which item to promote.

Jam then bread has a confidence of 100 percent, since both jam invoices include bread. It sounds dramatic, but it rests on two invoices. Confidence on a rare antecedent is fragile, which is another reason to keep a minimum support.

Lift: is it more than chance would produce?

Confidence has a blind spot. If an item is in almost every basket, anything will have high confidence toward it. Lift corrects for that: it is the confidence divided by how common the consequent is overall.

For bread and butter, confidence is 0.667 and butter appears in 0.5 of all invoices. Lift is 0.667 / 0.5 = 1.33. Bread buyers are a third more likely than average to buy butter. For bread and milk, confidence is 2 of 6, or 0.33, against milk’s overall 0.5, so lift is 0.67. Bread buyers are less likely than average to add milk. The two items are not complements; if anything they are mild substitutes for the shopping trip. A lift of 1 means no association, above 1 a positive one, below 1 a negative one.

Tea and biscuits give a lift of 1.67 (confidence 0.33 divided by biscuits at 0.2), and yet support is 0.10, a single invoice. High lift, tiny evidence. You need both numbers: support to say there is enough data, lift to say the link is not just popularity.

Turning rules into decisions

The rule “bread, butter” suggests keeping the two close on the shelf, or bundling them, or showing butter when bread is added to an online cart. But a few cautions apply.

  • Association is not causation. Customers buy bread and butter together because of breakfast, not because of your layout. A bundle may add little if they would have bought both anyway.
  • Obvious rules are common. Real datasets produce thousands of rules, most of them things the store manager already knows. Sort by lift and look for the surprising ones with adequate support.
  • Baskets differ by context. A weekend family shop and a quick evening top-up have different patterns; mixing them can blur or hide rules. Segment by store, time or customer type before mining.
  • Prices and margins matter. A high-lift pair of two low-margin items may be worth less than a modest-lift pair that includes a high-margin one.

In practice, the Apriori and FP-Growth algorithms find frequent itemsets efficiently so that you do not enumerate every combination, but the three measures above are the whole interpretive toolkit. If you can compute them on ten invoices, you can read the output of any library on ten million.

Figures and names in the examples are illustrative.

Leave a Reply

Trending