Association Rule Learning: A Beginner’s Guide to Apriori
Association rule learning is a type of unsupervised learning technique used in machine learning and data mining. This means we do not feed the algorithm labelled data and ask it to predict a category. Instead, we let it discover patterns on its own.
The classic use case is what’s called a market basket analysis: given what a customer has already put in their basket, what else are they likely to buy?
This has massive value in e-commerce and retail, and it became one of the earliest large-scale commercial applications of data-driven prediction in industry. Companies could analyse purchasing patterns to recommend products, arrange shelves strategically, and better understand customer behaviour.
Where Does “Data Mining” Fit In?
You’ll often see association rule learning mentioned alongside the term data mining.
Data mining is a subfield of data science focused on extracting useful patterns and insights from large datasets, whether that data comes from transaction records, clickstreams, databases, or elsewhere. It predates much of what we now call modern machine learning, and in the early days of e-commerce, companies were already using association rule learning to drive recommendation systems long before “ML” became a mainstream term.
Back then, many techniques involving pattern discovery and prediction were grouped under the umbrella of data mining. Today we use more precise terminology, but the two concepts are still closely connected.
So What Is Association Rule Learning, Exactly?
At its core, association rule learning is about discovering what tends to go with what.
If customers who buy bread and butter also tend to buy jam, that’s an association rule:
{bread, butter} → {jam}
In simple terms, the rule says:
“When bread and butter are purchased together, jam is also likely to be purchased.”
To measure how useful a rule actually is, three metrics do most of the heavy lifting.
1. Support
Support measures how often a combination appears in the dataset overall.
If only 2 out of 10,000 customers bought bread and butter together, the rule may not be worth paying attention to.
A high-support rule affects a meaningful portion of transactions.
2. Confidence
Confidence measures how reliable the rule is.
For example:
Of all the customers who bought bread and butter, how many also bought jam?
The higher the confidence, the more dependable the relationship appears to be.
3. Lift
Lift measures whether the relationship is genuinely meaningful or simply a coincidence.
Some products are naturally popular on their own. Lift helps us distinguish genuinely connected items from products that just happen to sell frequently.
- A lift greater than 1 means the items appear together more often than expected by chance.
- A lift of exactly 1 means there is no meaningful relationship.
- A lift below 1 suggests the items may actually occur together less often than expected.
Together, these three metrics help filter out noise and focus on rules that are actually actionable.
The Apriori Algorithm
The most well-known algorithm for association rule learning is called Apriori.
The name comes from the Latin phrase a priori, meaning “from what comes before” or “based on prior knowledge.”
That is precisely how the algorithm works. It uses what it already knows about frequent item combinations to narrow down where to search next.
The key insight behind Apriori is:
If people rarely buy pineapple and mango together, there’s no point checking whether they buy pineapple, mango, and orange together — that trio can only be rarer.
Think about it this way:
If customers rarely buy pineapple and mango together, then it is extremely unlikely that pineapple, mango, and orange together will suddenly become a frequent combination.
So instead of checking every possible combination of products, the algorithm aggressively removes unlikely candidates early.
This idea is known as the downward closure property, and it is what makes Apriori computationally efficient.
Don’t worry, if it’s not clear yet, we’re about to look at how apriori works.
In practice, Apriori works in stages.
Step 1: Start with Single Items
The algorithm first counts how often each individual item appears.
Any item that does not meet a minimum support threshold gets discarded.
For example, if we require items to appear in at least 5% of transactions, then any product appearing less frequently than that gets removed immediately.
Get Jeremiah J. U. Omueti’s stories in your inbox
Join Medium for free to get updates from this writer.
The remaining items become the foundation for the next step.
Step 2: Build Pairs
Next, the algorithm combines the remaining frequent items into pairs.
It then counts how often each pair appears together and again removes any pair that falls below the support threshold.
Step 3: Build Larger Groups
The same process continues with triplets, quadruplets, and larger item combinations.
At every stage, Apriori prunes aggressively.
If a smaller combination is infrequent, there is no reason to check larger combinations containing it because they can only occur less frequently.
This pruning process is what keeps the problem manageable, even when working with thousands of products.
A Quick Example
Suppose you run a small grocery store and track the following five transactions:
- Transaction Item 1:Bread, Butter
- Transaction Item 2: Jam2Bread
- Transaction Item 3: Butter3Bread
- Transaction Item 4: Jam4Butter
- Transaction Item 5: Jam5Bread
- Transaction Item 6: Butter, Jam
Now, imagine we set a support threshold of 60%, meaning an item combination must appear in at least 3 out of the 5 transactions to qualify as “frequent.”
Here’s what we get:
- Bread appears in 4 transactions → ✔️
- Butter appears in 4 transactions → ✔️
- Jam appears in 4 transactions → ✔️
- {Bread, Butter} appears in 3 transactions → ✔️
- {Bread, Jam} appears in 3 transactions → ✔️
- {Butter, Jam} appears in 3 transactions → ✔️
- {Bread, Butter, Jam} appears in 2 transactions → ❌
Notice something important here:
Even though all three pair combinations are frequent, the triple combination is not frequent enough to pass the threshold.
Now, let’s calculate confidence for one rule:
{Bread, Butter} → {Jam}
Bread and Butter appear together 3 times.
Out of those 3 transactions, Jam also appears 2 times.
So the confidence is:
This means that roughly two-thirds of customers who bought bread and butter also bought jam.
That is a useful signal, but not a perfect relationship.
One Thing to Know About Apriori’s Limitations
Apriori is intuitive and relatively easy to understand, but it can become computationally expensive as the number of products grows.
Why?
Because the number of possible item combinations increases extremely quickly.
With hundreds or thousands of products, generating and checking every candidate combination becomes expensive in both time and memory.
That is why more efficient algorithms like FP-Growth were developed later.
Still, Apriori remains one of the best places to begin conceptually because the logic is clean, intuitive, and easy to follow.
Final Thoughts
Association rule learning is one of those techniques that feels almost obvious once you understand it, and that is part of what makes it so powerful.
Humans naturally think in associations:
- People who buy running shoes may also buy sports socks.
- Customers who order burgers may also order soft drinks.
- Viewers who watch one movie genre may also prefer similar genres.
The Apriori algorithm simply scales that kind of reasoning to thousands or even millions of transactions at a level no human analyst could realistically handle.
And despite being one of the older techniques in machine learning and data mining, it still plays an important role in recommendation systems, retail analytics, and customer behaviour analysis today.










