Sitemap
Adarshajay

Adarshajay

📊 Association Rule Learning: Apriori, ECLAT, and FP-Growth Explained

3 min readMay 6, 2025

--

Press enter or click to view image in full size

Have you ever wondered how Amazon knows that people who buy a phone also buy a phone case? This magic comes from Association Rule Learning, a machine learning technique used to discover interesting relationships between variables in large datasets.

Let’s break it down in a way that even a non-technical reader can understand.

🤝 What Is Association Rule Learning?

Association Rule Learning is about finding hidden patterns or relationships in data — especially useful in market basket analysis, where retailers want to know what products are often bought together.

🔑 Key Terms You Should Know

Before diving into the algorithms, here are three important terms:

Term Meaning Support How frequently an item or itemset appears in the dataset. Confidence How often the rule is true (e.g., if A then B). Lift How much more likely B is to be bought when A is bought.

🧠 Example Dataset

Imagine a small grocery store dataset of 5 transactions:

Transaction Items Bought T1 Milk, Bread, Butter T2 Bread, Butter T3 Milk, Bread T4 Milk, Butter T5 Bread, Butter, Jam

Now we want to find patterns like:

Get Adarshajay’s stories in your inbox

Join Medium for free to get updates from this writer.

“If someone buys Bread and Butter, they are also likely to buy Jam.”

🧮 1. Apriori Algorithm

💡 How It Works:

  • Starts with individual items
  • Combines them to form pairs, triplets, etc.
  • Eliminates combinations that don’t meet a minimum support
  • Repeats this process

✅ Example:

  1. Count how often each item appears (Support)
  2. Filter out items below minimum support (say, 60%)
  3. Combine frequent items to form larger sets
  4. Generate rules like:

{Bread, Butter} → {Jam}
Support: 20% | Confidence: 50%

🔍 Pros:

  • Easy to understand
  • Good for small datasets

⚠️ Cons:

  • Scans the database many times
  • Slower on large data

🌲 2. ECLAT Algorithm

💡 How It Works:

  • Uses Vertical Layout: keeps track of which transactions contain each item (TID list)
  • Finds frequent itemsets using set intersections

✅ Example:

  • Milk: {T1, T3, T4}
  • Bread: {T1, T2, T3, T5}
  • Milk ∩ Bread = {T1, T3} → Support = 2

{Milk, Bread} is frequent if support ≥ 2

🔍 Pros:

  • Faster than Apriori
  • Reduces number of scans

⚠️ Cons:

  • Uses more memory (stores all transaction IDs)

⚡ 3. FP-Growth Algorithm

💡 How It Works:

  • Builds a compact tree structure called FP-Tree
  • Avoids generating all possible item combinations
  • Recursively mines frequent patterns from the tree

✅ Example:

It compresses the dataset into a tree like this:

Milk → Bread → Butter
Bread → Butter
Milk → Bread
Milk → Butter
Bread → Butter → Jam

Then, it efficiently finds patterns from this structure.

{Bread, Butter} → {Jam} is discovered without scanning the dataset repeatedly.

🔍 Pros:

  • Very fast and scalable
  • Efficient with large datasets

⚠️ Cons:

  • FP-Tree can be hard to build and manage in memory

🔄 Summary Comparison

Algorithm DB Scans Memory Use Speed Best Use Case Apriori Multiple Low Slow Small datasets ECLAT Few Medium Medium Dense datasets FP-Growth 1–2 High Very Fast Large-scale pattern mining

💡 Real-Life Applications

  • 🛒 Retail: Suggesting products to add to a shopping cart
  • 🎶 Streaming: Recommending songs based on listening history
  • 🏥 Healthcare: Finding co-occurring symptoms or treatments
  • 📚 E-learning: Suggesting courses based on learning paths

🧾 Conclusion

Association Rule Learning helps us uncover patterns in data that are not obvious. Each algorithm has its strengths:

Implementation of the algorithm — https://github.com/achuajays/Machine-Learning/blob/main/Step_by_Step_Implementation_using_mlxtend.ipynb

  • Use Apriori when learning or working with small datasets.
  • Use ECLAT if you want better speed and handle memory well.
  • Use FP-Growth for performance on big data.

--

--