š Introduction
Association Rule Learning is an unsupervised machine learning technique used to discover interesting relationships, patterns, and associations among items in large transactional datasets. Instead of predicting labels, it identifies rules that describe how items frequently occur together.
The three most widely used association rule mining algorithms are Apriori, FP-Growth (Frequent Pattern Growth), and Eclat (Equivalence Class Clustering and Bottom-up Lattice Traversal).
Information
šÆ Learning Objectives
- Understand Association Rule Learning.
- Learn the concepts of support, confidence, and lift.
- Understand Apriori, FP-Growth, and Eclat algorithms.
- Compare the three algorithms and their applications.
š What is Association Rule Learning?
Association Rule Learning discovers relationships of the form:
Which means:
- If itemset A occurs, itemset B is likely to occur as well.
For example:
Customers purchasing bread often purchase butter.
| Characteristic | Association Rule Learning |
|---|---|
| Learning Type | Unsupervised |
| Main Goal | Discover Item Relationships |
| Requires Labels | No |
| Typical Dataset | Transactional Data |
š Key Concepts
| Concept | Description |
|---|---|
| Item | Single product or object. |
| Itemset | Collection of multiple items. |
| Transaction | Collection of purchased items. |
| Frequent Itemset | Itemset appearing frequently in transactions. |
| Association Rule | Relationship between two itemsets. |
š Support
Support measures how frequently an itemset appears in the dataset.
Remember
š Confidence
Confidence measures how often itemset B appears when A appears.
š Lift
Lift measures the strength of an association compared to random chance.
| Lift Value | Interpretation |
|---|---|
| > 1 | Positive association. |
| = 1 | No association. |
| < 1 | Negative association. |
š Apriori Algorithm
Apriori identifies frequent itemsets using the Apriori Principle:
Remember
How Apriori Works
Find all frequent 1-itemsets.
Generate larger candidate itemsets.
Calculate support for each candidate.
Prune candidates below the minimum support threshold.
Repeat until no larger frequent itemsets exist.
š² FP-Growth Algorithm
FP-Growth avoids generating candidate itemsets by compressing transactions into a compact Frequent Pattern Tree (FP-Tree).
Scan the dataset and compute item frequencies.
Construct the FP-Tree.
Recursively mine frequent patterns from the tree.
Generate association rules.
Tip
š Eclat Algorithm
Eclat uses a vertical database format, storing transaction identifiers (TIDs) for each item instead of transaction records.
Convert the database into vertical format.
Store transaction IDs for every item.
Intersect transaction ID lists to compute support.
Recursively generate larger frequent itemsets.
š³ Association Rule Learning Workflow
š Apriori vs FP-Growth vs Eclat
| Feature | Apriori | FP-Growth | Eclat |
|---|---|---|---|
| Candidate Generation | Yes | No | No |
| Database Scans | Multiple | Two | One Vertical Format |
| Main Data Structure | Candidate Itemsets | FP-Tree | Transaction ID Sets |
| Speed | Slow | Fast | Very Fast |
| Large Datasets | Moderate | Excellent | Excellent |
šļø Important Hyperparameters
| Hyperparameter | Description |
|---|---|
| min_support | Minimum support threshold. |
| min_confidence | Minimum confidence for association rules. |
| min_lift | Minimum lift value. |
| max_length | Maximum size of generated itemsets. |
š Rule Evaluation Metrics
| Metric | Purpose |
|---|---|
| Support | Frequency of occurrence. |
| Confidence | Reliability of a rule. |
| Lift | Strength beyond random chance. |
| Leverage | Difference from independence. |
| Conviction | Measures rule implication. |
āļø Advantages and Limitations
- Discovers hidden purchasing patterns.
- No labeled data required.
- Easy to interpret association rules.
- Widely used in recommendation systems.
- Supports business decision-making.
- Can generate a very large number of rules.
- Apriori becomes slow for dense datasets.
- Choosing appropriate thresholds is challenging.
- Association does not imply causation.
š Real-World Applications
| Application | Purpose |
|---|---|
| š Market Basket Analysis | Identify products frequently purchased together. |
| š¬ Recommendation Systems | Recommend related products or content. |
| šŖ Retail Inventory Planning | Optimize product placement and stocking. |
| š Web Usage Mining | Analyze navigation patterns. |
| š³ Fraud Detection | Discover unusual transaction combinations. |
| š„ Healthcare Analytics | Identify frequently co-occurring diseases and treatments. |
š» Practical Example
Apriori Association Rule Mining Using mlxtend
import pandas as pd
from mlxtend.frequent_patterns import apriori, association_rules
# Sample one-hot encoded transaction dataset
data = pd.DataFrame({
"Bread": [1,1,1,0,1],
"Milk": [1,1,0,1,1],
"Butter": [1,0,1,1,1],
"Eggs": [0,1,1,1,0]
})
# Find frequent itemsets
frequent_itemsets = apriori(
data,
min_support=0.4,
use_colnames=True
)
# Generate association rules
rules = association_rules(
frequent_itemsets,
metric="confidence",
min_threshold=0.7
)
print(frequent_itemsets)
print(rules[["antecedents","consequents","support","confidence","lift"]])ā ļø Common Mistakes
- Confusing correlation with causation.
- Using a minimum support threshold that is too high or too low.
- Interpreting rules based only on confidence while ignoring lift.
- Generating excessive numbers of insignificant rules.
- Applying Apriori to very large datasets where FP-Growth or Eclat would be more efficient.