Find cross-selling opportunities with market basket analysis
Mine association rules from transactions, interpret support, confidence and lift, and turn rules into bundles, recommendations and placement.
Which products are bought together? The answer drives “frequently bought together” recommendations, bundles, store layout, cross-promotion and even which products to discount. Market basket analysis finds these patterns in transaction data with association rules.
Association rules
A rule has the form If {antecedent} then {consequent}: “if a basket contains beer and salsa, it also contains chips”. Three measures describe a rule:
- Support: the share of all baskets that contain both sides. A rule with 1.88% support is based on 45 of 2,400 baskets.
- Confidence: among baskets with the antecedent, the share that also contain the consequent. 88.2% of baskets with beer and salsa also contain chips.
- Lift: confidence divided by the overall share of baskets with the consequent. Lift = 1 means no association; lift = 7.73 means chips are 7.7 times as likely in beer-and-salsa baskets as in an average basket.
Confidence alone is misleading for popular items: almost every rule ending in “bread” has high confidence simply because most baskets contain bread. Lift corrects for that and is the measure to sort by.
Find products bought together
- 2,400 grocery baskets with 24 products.
- Read the top association rules sorted by lift.
- Change the minimum support or confidence and watch the number of rules change.
Reading the example
The example has 2,400 grocery transactions with 24 products (2.73 items per basket). With the default thresholds, the Apriori algorithm finds 197 frequent itemsets and 126 rules. The strongest:
- Parmesan + Tomato sauce → Pasta: support 1.92%, confidence 100%, lift 11.43. Every basket with parmesan and tomato sauce also had pasta.
- Bananas + Chips → Salsa: confidence 66.7%, lift 8.29, but support only 1.08% (26 baskets); an interesting but thin pattern.
- Beer + Salsa → Chips: confidence 88.2%, lift 7.73, 45 baskets.
- The strongest pairwise rule is Shampoo → Toothpaste: 44.0% of baskets with shampoo also contain toothpaste, 6.95 times the base rate.
Note the asymmetry: Pasta → Parmesan + Tomato sauce has the same lift (11.43) but a confidence of only 21.9%, because most pasta buyers do not buy both. Direction matters for recommendations: show pasta to people with sauce and parmesan in the basket, not the other way round.
Choosing the thresholds
Minimum support removes rare combinations that could be chance; minimum confidence removes weak rules. Too-high thresholds hide niche but valuable patterns; too-low thresholds produce thousands of rules. Start with support around 1% and confidence around 20 to 30%, sort by lift, and look at the count behind each rule. Leverage and conviction are additional measures: leverage is the difference between observed and expected co-occurrence, and conviction rises as the rule is rarely violated (infinite when confidence is 100%).
From rules to actions
- Recommendations: “customers who bought X also bought Y” on product pages and in the cart.
- Bundles and meal deals: pasta, sauce and parmesan as one offer.
- Placement: put chips near salsa and beer, or deliberately apart to lead customers past other products.
- Promotions: discount one item of a strong pair and recover margin on the other; avoid discounting both.
Cautions
Association is not causation: discounting salsa will not necessarily sell more chips, because the shared cause may be a party. Test promotions before rolling them out (Lesson 6). Seasonal items create seasonal rules; analyse periods separately if the assortment changes. And very frequent items (bags, bread) can dominate; consider excluding them.
Reporting
Association rule mining (Apriori) on 2,400 transactions identified 126 rules. The strongest rule, parmesan and tomato sauce → pasta, had a confidence of 100% and a lift of 11.43 (support 1.92%). Beer and salsa were followed by chips in 88.2% of baskets (lift 7.73), suggesting a snack bundle for testing.
Key takeaways
- Support = how common; confidence = how reliable; lift = how much stronger than chance.
- Sort rules by lift and check the number of baskets behind each.
- Rules are directional; use the direction for recommendations.
- Rules show co-occurrence, not cause; test promotions before scaling them.
Check your understanding
Answer each question to see the explanation. Finishing the quiz marks this lesson as complete.