Skip to main content
Interactive PlaybookData Analysis · Recommendations · AI

Why Customers Buy Products Together

A basket of groceries contains more information than a shopping list. The combinations customers choose reveal purchasing patterns that can drive smarter recommendations, better product placement, and higher average order value — if you know how to read them.

267 purchase records
18 products
24 buying patterns discovered
No ML background required
Why customers buy products together
How to measure association strength vs. coincidence
How recommendation engines work under the hood
How to build this into a production system
Where AI enhances rule-based recommendations
How to apply this thinking to your own business data

Section 01 — The Business Problem

One purchase often predicts another

A customer buys a laptop. Within the same week, they also purchase a mouse, a keyboard, and a laptop bag. This is not a coincidence — it is a pattern. The question is whether your business can discover and act on patterns like this automatically.

A typical customer journey

💻
LaptopMain purchase
🖱️
MouseBought within same week
⌨️
KeyboardBought within same week
👜
Laptop BagBought within same week

If you sell 10,000 laptops and 70% of buyers purchase accessories within a week, that is a pattern worth acting on. The question is whether you know it exists.

Cross-selling

Show "frequently bought together" suggestions on the product page.

Smarter email

After a laptop purchase, send a timely accessory recommendation — not random promotions.

Inventory planning

Stock laptop bags and keyboards when laptops are promoted, because purchases correlate.

Product placement

Position accessories near laptops in-store and in category pages online.

Section 02 — The Dataset

What the data looks like

Before any analysis, it helps to understand what the raw data looks like. Purchase data is stored as transactions — each transaction is one basket, containing the items a customer bought together.

Transactions

267

Unique items

18

Avg basket size

3.0 items

Data source

Curated

Key concepts

Transaction

One purchase event. Everything a customer bought in a single visit or order. Also called a "basket."

T001: {milk, bread, eggs}

Item

A single product within a transaction. Items don't have quantities here — we only record whether something was bought.

"milk", "bread", "pasta"

Itemset

A combination of two or more items. We want to find itemsets that appear together more often than chance would predict.

{pasta, vegetables, red-meat}

Sample transactions (7 of 267)

TransactionItems in basket
T001
whole-milkbutteryogurt
T002
breadbuttercoffee
T003
pastavegetablesred-meat
T004
cheesewineherbs-spices
T005
ricechickenvegetables
T006
beerred-meatsoda
T007
chocolatecoffee

Item frequency — how often each product appears

🥛Whole Milk
26.6% (71)
🍞Bread
24.0% (64)
🥦Vegetables
23.6% (63)
🧀Cheese
18.7% (50)
🍗Chicken
18.0% (48)
Coffee
15.7% (42)
🍫Chocolate
15.7% (42)
🥚Eggs
15.0% (40)
🍷Wine
15.0% (40)
🥩Red Meat
14.6% (39)
🍍Tropical Fruit
14.2% (38)
🍚Rice
14.2% (38)
🫙Yogurt
13.9% (37)
🌿Herbs & Spices
13.9% (37)
🍝Pasta
12.4% (33)
🧈Butter
12.0% (32)
🥤Soda
12.0% (32)
🍺Beer
8.2% (22)

Dataset note: This is a curated 267-transaction dataset across 18 grocery items, designed to illustrate how association rule mining discovers distinct shopper profiles. For analysis on a real retail dataset, see the Python notebook which uses the UCI Online Retail Dataset .

Section 03 — Explore the Data

Loading explorer…

Section 04 — What Surprised Us

Patterns the data revealed

These findings come from running the actual analysis on our curated dataset. Every claim here is derived from the computed association rules — nothing invented.

Strongest 2-item rule

Beer and soda: 100% confidence

In our expanded dataset, every basket containing beer also contained soda — 100% confidence, lift 8.3×. The strongest 2-item rule we found. This does not mean beer causes soda purchases. It means these two items co-occur perfectly consistently in our data.

Bidirectional cluster

Rice and chicken pull bidirectionally

78.9% of rice baskets include chicken. 62.5% of chicken baskets include rice. Lift 4.4× in both directions — a coherent meal-prep pattern, not a one-way recommendation. Most association rules are asymmetric; this one is not.

Counterintuitive

Popular items have weaker associations

Whole milk appears in 25% of all baskets — the most purchased item by far. But most milk-related rules have lift below 2.5. High frequency means it co-occurs with everything, so it has weak predictive value. Popularity is not the same as association strength.

Section 05 — How the Algorithm Works

Three numbers that explain everything

The Apriori algorithm discovers association rules in transaction data. You do not need to understand the algorithm to use its output — but understanding these three measurements makes every rule interpretable.

SupportHow often does this combination appear?

Formula

transactions containing {A and B} ÷ total transactions

Example from our data

Pasta AND vegetables appear together in 25 of 120 baskets.

Support = 25/120 = 20.8%

When to use it

Use support to filter out rare combinations that might just be noise. A high-support itemset appears frequently enough to be worth acting on.

ConfidenceWhen someone buys A, how often do they also buy B?

Formula

transactions containing {A and B} ÷ transactions containing {A}

Example from our data

Of 20 wine transactions, all 20 also contain cheese.

Confidence = 20/20 = 100%

When to use it

Confidence measures the reliability of the rule as a prediction. But a 100% confidence rule on a product that everyone buys (like whole milk) is less meaningful.

LiftIs the association real, or just because both products are popular?

Formula

confidence ÷ (support of B alone)

Example from our data

Cheese support alone = 25%. Wine → Cheese confidence = 100%.

Lift = 100% ÷ 25% = 4.0×

When to use it

Lift > 1.0 means the association is stronger than chance. Lift = 1.0 means independence. Lift < 1.0 means the products are less likely to appear together than expected.

Why you always need lift

In our dataset, the rule "bread → whole-milk" has high confidence (~50%) — but lift is only 1.36. Whole milk appears in 37% of all baskets regardless. Bread barely changes the odds. Compare to "wine → cheese": confidence 100%, lift 4.0. That is a real association. Without lift, you would act on both equally. With lift, you know which one matters.

Section 06 — The Analysis Results

The buying patterns discovered

These are the actual association rules computed from our curated dataset, sorted by lift. Every number here is reproducible — run the Python notebook to verify.

Reading this table

Each row is one rule: IF a customer buys the items on the left, THEN they frequently also buy the items on the right. Rules are sorted by lift — the higher the lift, the more the association exceeds random chance.

If customer buysThey also buySupportConfidenceLift
BeerSoda8.2%100%
8.34×
SodaBeer8.2%69%
8.34×
CheeseWine15.0%80%
5.34×
WineCheese15.0%100%
5.34×
YogurtTropical Fruit9.4%68%
4.75×
Tropical FruitYogurt9.4%66%
4.75×
ChickenRice11.2%63%
4.39×
RiceChicken11.2%79%
4.39×
ChickenHerbs & Spices9.4%52%
3.76×
Herbs & SpicesChicken9.4%68%
3.76×
PastaVegetables9.4%76%
3.21×
VegetablesPasta9.4%40%
3.21×
ChocolateCoffee7.5%48%
3.03×
CoffeeChocolate7.5%48%
3.03×
Whole MilkYogurt10.9%41%
2.95×

Section 07 — Production Architecture

How a company would build this

Running Apriori on a CSV in a notebook is one thing. Serving live recommendations to thousands of users is another. Here is one practical architecture for taking association rules into production.

01

Order Data

Database / Event stream

Each completed order is an event: order_id, customer_id, list of product_ids, timestamp.

02

Data Pipeline

ETL job · Airflow / dbt

Extract orders, group by transaction, filter to complete orders, deduplicate, format as item lists.

03

Association Analysis

Python · mlxtend / pyfpgrowth

Run Apriori or FP-Growth on the transaction list with chosen support/confidence/lift thresholds. Rerun on a schedule as new orders arrive.

04

Rules Store

Redis / Postgres

Store the discovered rules in a fast lookup structure. Index by antecedent product ID for O(1) lookup at request time.

05

Recommendation API

REST / GraphQL

Given the current cart or viewed product, query the rules store and return ranked recommendations filtered by lift threshold.

06

Product Surface

Frontend / Email

Display recommendations on product pages, cart sidebars, checkout pages, or post-purchase emails.

Practical considerations

Recompute frequency

Daily batch jobs work for most businesses. Hourly for high-volume retail.

Minimum thresholds

Start with lift > 1.5. Too low = noise. Too high = too few rules.

Cold start

New products have no history. Use content-based fallbacks (category, brand) until data accumulates.

Scalability

FP-Growth is faster than Apriori at scale. For millions of transactions, consider distributed variants on Spark.

Section 08 — AI Opportunities

How AI enhances recommendations

Association rules are a foundation. AI adds context, conversation, and personalisation on top of that foundation. Neither replaces the other — they work in layers.

Example: AI-powered shopping assistant

I'm buying a gaming laptop. What else should I get?

Based on what other customers usually buy with gaming laptops, you might want a gaming mouse and keyboard — those appear together in most gaming setups. A cooling pad is also worth considering if you plan to use it for long sessions. Do you already have a monitor?

Sources used:

Association rules: gaming laptop → mouse (conf 82%)Association rules: gaming laptop → keyboard (conf 74%)Product metadata: cooling accessories categoryCatalog: current inventory check

What the AI combines

Association rules

Historically co-purchased products, ranked by lift

Product metadata

Category, compatibility, brand relationships

Customer history

What this specific customer has already bought

Catalog context

Current inventory, promotions, pricing

Traditional rule-based

"You may also like" — shows top 4 associated products regardless of context.

Same recommendations for all customers. No conversational context.

AI-enhanced

Natural language query → combines rules + metadata + history → personalized, contextual response.

Requires more infrastructure. Rules still needed as the foundation.

Section 10 — Apply to Your Business

What patterns exist in your data?

Market basket analysis is not limited to grocery stores. Anywhere you have transaction records — features used, activities completed, courses taken, products purchased — the same technique applies.

🛒

Ecommerce

Dataset: Order history

Which products should be recommended together?

DatasetOrder items grouped by order_id
Pattern{product A} → {product B, C}
DecisionShow "Frequently bought together" on product pages
Every ecommerce store with more than a few months of order data can run this analysis. The patterns exist in your data — the question is whether you are reading them.
⚙️

SaaS Product

Dataset: Feature usage logs

Which features are adopted together? What should be recommended next?

DatasetCustomer → features used (this month)
Pattern{API, SSO} → {Webhooks}
DecisionSurface Webhooks in onboarding for API + SSO users
Feature adoption patterns reveal natural upgrade paths. Users who use API and SSO together are candidates for Webhooks — not because you guessed it, but because the data shows it.
📊

CRM / Sales

Dataset: Lead activity history

What activities commonly occur before conversion?

DatasetLead → activities completed (demo, proposal, pricing...)
Pattern{demo, pricing page} → {closed won}
DecisionWhen a lead sees pricing after a demo, trigger a follow-up
Sales pipelines contain sequential patterns. Association mining on activity combinations (not sequences) surfaces which combinations of signals predict outcomes.
🎓

HR / Learning

Dataset: Training completion records

Which courses are commonly completed together?

DatasetEmployee → courses completed
Pattern{Python basics, data analysis} → {SQL fundamentals}
DecisionRecommend SQL when Python + data analysis are complete
Learning paths are not purely linear. Association mining discovers which course combinations appear together in high-performing employees — then you build that path for everyone.

The question to ask yourself

What are the “transactions” in your business? What are the “items”? If you can answer those two questions, you can run this analysis. The patterns are already in your data. You just have not looked for them yet.