Unit 5: Association Rule Mining

Syllabus

5.1 Introduction to Association Rule Mining

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:

Key Terminology

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))

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(A → B) = (1 - Support(B)) / (1 - Confidence(A → B))
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

  1. Scan 1: Count support of all 1-itemsets. Remove those below min_sup to get L₁.
  2. Generate Candidates (Cₖ): Join Lₖ₋₁ with itself to produce candidate k-itemsets.
  3. Prune: Remove candidates containing any infrequent (k-1)-subset.
  4. Scan k: Count support of remaining candidates. Keep those above min_sup → Lₖ.
  5. Repeat steps 2-4 until no more frequent itemsets can be found.
  6. 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 and Weaknesses

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

  1. Scan 1: Count support of all 1-itemsets. Sort items in descending order of support.
  2. Scan 2: For each transaction, insert items into the FP-tree in sorted order. Shared prefixes are merged.
  3. Header Table: Maintain a linked list for each item pointing to its occurrences in the tree for traversal.

Frequent Pattern Mining

  1. Start from the least frequent item in the header table.
  2. Follow the header links to find all paths containing that item.
  3. Construct a conditional FP-tree for that item by accumulating path counts and removing infrequent items.
  4. 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

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.
Unit 4 Activity Case Studies