Association Rule Mining (also called Market Basket Analysis) discovers interesting relationships, patterns, and co-occurrences among items in large transactional databases. It answers the question: "What items are frequently bought together?"
Transactional Database
A transactional database is a collection of transactions, where each transaction is a set of items (an itemset). For example:
Transaction T1: {Milk, Bread, Eggs}
Transaction T2: {Bread, Diapers, Beer, Lettuce}
Transaction T3: {Milk, Diapers, Beer, Coke}
Transaction T4: {Bread, Milk, Diapers, Beer}
Transaction T5: {Bread, Milk, Diapers, Coke}
Key Terminology
Itemset: A collection of one or more items. An itemset with k items is a k-itemset.
Support Count (σ): The frequency of occurrence of an itemset in the database.
Minimum Support (min_sup): A threshold — only itemsets occurring at least this frequently are considered frequent.
Frequent Itemset: An itemset whose support count ≥ min_sup.
Association Rule: An expression of the form A → B, where A and B are disjoint itemsets.
Core Problem: Given a set of transactions T, find all rules that meet minimum support (min_sup) and minimum confidence (min_conf) thresholds. The brute-force approach is infeasible for large databases — efficient algorithms like Apriori and FP-Growth are essential.
1
Apriori Algorithm Process
graph TD
START[Start: Transaction Database] --> SCAN1[Scan DB Count support of 1-itemsets]
SCAN1 --> FREQ1[Frequent 1-itemsets Remove items below min_sup]
FREQ1 --> CAND[Generate Candidates Join frequent (k)-itemsets]
CAND --> PRUNE[Prune Candidates Apply anti-monotonicity property]
PRUNE --> SCAN2[Scan DB Count support of candidates]
SCAN2 --> CHECK{Frequent Itemsets Found?}
CHECK -->|Yes| FREQK[Frequent k-itemsets Keep itemsets above min_sup]
FREQK --> CAND
CHECK -->|No| RULES[Generate Rules From all frequent itemsets]
RULES --> FILTER[Filter Rules Apply min_conf threshold]
FILTER --> OUTPUT[Association Rules A → B with support, confidence]
classDef decision fill:#dc2626,stroke:#ef4444,color:#fff,font-size:18px,font-weight:bold
classDef process fill:#0891b2,stroke:#22d3ee,color:#fff,font-size:18px,font-weight:bold
classDef success fill:#22c55e,stroke:#4ade80,color:#fff,font-size:18px,font-weight:bold
classDef warning fill:#f59e0b,stroke:#fbbf24,color:#1e1b4b,font-size:18px,font-weight:bold
class CHECK decision
class SCAN1,SCAN2,CAND,PRUNE,RULES,FILTER process
class START,FREQ1,FREQK,OUTPUT success
Note: The Apriori algorithm iteratively generates and prunes candidate itemsets. The anti-monotonicity property states: if an itemset is infrequent, all its supersets must also be infrequent — enabling powerful pruning.
5.2 Key Metrics
Association rules are evaluated using four key metrics that measure the strength, quality, and usefulness of discovered relationships.
Support
Support measures how frequently the itemset appears in the database. It indicates the statistical significance of a rule.
Support(A → B) = P(A ∪ B) = count(A ∪ B) / N
where N is the total number of transactions. Low support means the rule may be accidental — it captures too few transactions to be actionable.
Confidence
Confidence measures the reliability of the rule. It tells us: given that A is purchased, what is the probability B is also purchased?
Confidence(A → B) = P(B|A) = Support(A ∪ B) / Support(A)
High confidence means the rule is strong — A and B co-occur consistently. However, confidence alone can be misleading if B is very popular.
Lift
Lift corrects confidence by accounting for the baseline popularity of B. It measures how much more likely B is when A is present, compared to B's overall frequency.
Lift(A → B) = Confidence(A → B) / Support(B) = Support(A ∪ B) / (Support(A) × Support(B))
Lift > 1: A and B are positively correlated — A increases the likelihood of B.
Lift = 1: A and B are independent — no association.
Lift < 1: A and B are negatively correlated — A decreases the likelihood of B.
Conviction
Conviction measures the degree to which the antecedent (A) and consequent (B) are associated. It captures how wrong the rule would be if the relationship were random.
Conviction = ∞: The rule is always correct (confidence = 1).
Conviction > 1: The rule is better than random.
Conviction = 1: A and B are independent.
Best Practice: Use all metrics together. High support ensures statistical significance, high confidence ensures reliability, high lift confirms the relationship is not spurious, and high conviction indicates rule quality. A rule with high confidence but low lift may simply reflect a popular item.
5.3 Apriori Algorithm
The Apriori algorithm (Agrawal & Srikant, 1994) is the foundational algorithm for frequent itemset mining. It uses a level-wise, breadth-first approach with the anti-monotonicity (Apriori) property for pruning.
Anti-Monotonicity Property
If an itemset is infrequent, all its supersets must also be infrequent. This is the core insight that makes Apriori efficient. Once an itemset is found to be below min_sup, we can eliminate all larger itemsets containing it without counting them.
Algorithm Steps
Scan 1: Count support of all 1-itemsets. Remove those below min_sup to get L₁.
Generate Candidates (Cₖ): Join Lₖ₋₁ with itself to produce candidate k-itemsets.
Prune: Remove candidates containing any infrequent (k-1)-subset.
Scan k: Count support of remaining candidates. Keep those above min_sup → Lₖ.
Repeat steps 2-4 until no more frequent itemsets can be found.
Generate Rules: From all frequent itemsets, generate rules meeting min_conf.
Example Walkthrough
Given min_sup = 2 (itemset must appear in at least 2 of 5 transactions):
Strengths: Simple to understand and implement. Correctness guaranteed. Works well for dense datasets with small itemsets.
Weaknesses: Generates many candidates (especially with long frequent itemsets). Requires multiple database scans (one per k). Can be slow for large, sparse datasets.
5.4 FP-Growth Algorithm
The FP-Growth algorithm (Han, Pei & Yin, 2000) mines frequent patterns without candidate generation. It compresses the database into a compact tree structure called the FP-tree, then extracts frequent patterns directly.
FP-Tree Construction
Scan 1: Count support of all 1-itemsets. Sort items in descending order of support.
Scan 2: For each transaction, insert items into the FP-tree in sorted order. Shared prefixes are merged.
Header Table: Maintain a linked list for each item pointing to its occurrences in the tree for traversal.
Frequent Pattern Mining
Start from the least frequent item in the header table.
Follow the header links to find all paths containing that item.
Construct a conditional FP-tree for that item by accumulating path counts and removing infrequent items.
Recursively mine the conditional FP-tree to extract all frequent patterns ending with that item.
Why FP-Growth is Faster:
Only two database scans (vs. k scans in Apriori).
No candidate generation — avoids the expensive generate-and-test cycle.
Compressed tree representation uses less memory than storing all candidates.
Conditional pattern mining is divide-and-conquer — decomposes the problem into smaller subproblems.
2
FP-Tree Construction and Mining
graph TD
DB[Transaction Database] --> SCAN[Scan 1: Count 1-itemsets Sort by support desc]
SCAN --> HEADER[Header Table Item → Support → Pointer]
HEADER --> BUILD[Scan 2: Build FP-Tree Insert sorted items, share prefixes]
BUILD --> TREE[FP-Tree Compressed frequent patterns]
TREE --> LEAST[Least Frequent Item Start from bottom]
LEAST --> PATHS[Find All Paths Follow header links]
PATHS --> COND[Conditional FP-Tree Accumulate counts, prune infrequent]
COND --> RECURSE{Conditional Tree Non-Empty?}
RECURSE -->|Yes| LEAST
RECURSE -->|No| PATTERNS[Frequent Patterns All patterns ending with item]
classDef decision fill:#dc2626,stroke:#ef4444,color:#fff,font-size:18px,font-weight:bold
classDef process fill:#0891b2,stroke:#22d3ee,color:#fff,font-size:18px,font-weight:bold
classDef success fill:#22c55e,stroke:#4ade80,color:#fff,font-size:18px,font-weight:bold
classDef warning fill:#f59e0b,stroke:#fbbf24,color:#1e1b4b,font-size:18px,font-weight:bold
class RECURSE decision
class SCAN,BUILD,PATHS,COND process
class DB,HEADER,TREE,LEAST,PATTERNS success
Note: The FP-tree stores all frequent itemset information in a compressed structure. Mining proceeds bottom-up from the least frequent item, building conditional trees that progressively narrow the search space.
Apriori vs FP-Growth Comparison
Scans: Apriori requires k scans (one per level); FP-Growth requires exactly 2 scans.
Candidates: Apriori generates and tests candidates; FP-Growth avoids candidates entirely.
Data Structure: Apriori uses hash trees or vertical formats; FP-Growth uses a compact FP-tree.
Performance: FP-Growth is typically 1-2 orders of magnitude faster on large, sparse datasets.
Memory: FP-Growth may use more memory for very dense datasets due to tree overhead.
5.5 Applications
Association rule mining powers a wide range of real-world applications across industries:
Retail Cross-Selling
Supermarkets and e-commerce platforms use association rules to identify products that are frequently purchased together. Rules like {bread} → {butter} drive cross-selling strategies, store layout optimization, and promotional pricing. Amazon attributes over 35% of its revenue to association-based recommendations.
Recommendation Engines
Streaming platforms (Netflix, Spotify) and e-commerce sites use association rules combined with collaborative filtering to suggest items. "Users who liked X also liked Y" is a direct application of association rule mining. Spotify uses 40+ audio features alongside association rules to build its recommendation system.
Bioinformatics
Association rules are used to discover relationships between genes, proteins, and diseases. Gene co-expression patterns, protein-protein interactions, and drug side-effect correlations are all mined using association rule techniques.
Web Usage Mining
Web servers log user navigation paths. Association rules reveal common browsing patterns (e.g., users who visit the product page then the reviews page are likely to purchase). This informs website redesign, ad placement, and session prediction.
3
Association Rule Metrics Overview
graph TD
RULE[Association Rule A → B] --> SUP[Support Frequency of A∪B in transactions]
RULE --> CONF[Confidence P(B|A) Reliability of rule]
RULE --> LIFT[Lift Conf / Support(B) Correlation strength]
RULE --> CONV[Conviction (1-Sup(B))/(1-Conf) Dependency measure]
SUP --> SUP_T{Support ≥ min_sup?}
CONF --> CONF_T{Confidence ≥ min_conf?}
LIFT --> LIFT_T{Lift > 1?}
CONV --> CONV_T{Conviction > 1?}
SUP_T -->|Yes| KEEP1[Statistically Significant]
CONF_T -->|Yes| KEEP2[Reliable Rule]
LIFT_T -->|Yes| KEEP3[Positive Correlation]
CONV_T -->|Yes| KEEP4[Strong Dependency]
SUP_T -->|No| REJECT[Reject Rule]
CONF_T -->|No| REJECT
LIFT_T -->|No| SPURIOUS[Spurious Association]
classDef decision fill:#dc2626,stroke:#ef4444,color:#fff,font-size:18px,font-weight:bold
classDef process fill:#0891b2,stroke:#22d3ee,color:#fff,font-size:18px,font-weight:bold
classDef success fill:#22c55e,stroke:#4ade80,color:#fff,font-size:18px,font-weight:bold
classDef warning fill:#f59e0b,stroke:#fbbf24,color:#1e1b4b,font-size:18px,font-weight:bold
classDef error fill:#ef4444,stroke:#f87171,color:#fff,font-size:18px,font-weight:bold
class SUP_T,CONF_T,LIFT_T,CONV_T decision
class RULE,SUP,CONF,LIFT,CONV process
class KEEP1,KEEP2,KEEP3,KEEP4 success
class REJECT,SPURIOUS error
Note: No single metric is sufficient. Support filters statistically insignificant rules. Confidence measures reliability. Lift detects spurious correlations. Conviction captures dependency. Always evaluate rules using multiple metrics together.