Chapter 7
Association Analysis
Frequent patterns and market basket analysis, support, confidence and lift, the Apriori algorithm with candidate generation and pruning, and FP-Growth with the FP-tree.
From: MOOC - DM introduction: measures (Association Analysis), Topic 7b - Frequent Patterns and Apriori Algorithm, Topic 7c - FP-Growth Algorithm
What is association analysis? (measures deck)
- Finding frequent patterns, associations, correlations or causal structures among sets of items in transactional, relational and other databases. Features are called items.
- Frequent pattern: a pattern (set of items, sequence…) that occurs frequently; features that occur together or are correlated.
- Applications: market basket analysis for cross-marketing, web log (click stream) analysis, DNA sequences, document summarization, plagiarism detection (baskets = documents, items = sentences), drug side-effects (baskets = patients).
Market basket analysis
- The earliest form of frequent itemset mining: examine the products bought by thousands of consumers.
- Stores place related products together; direct marketers decide which new products to offer; inventory reorder points reflect demand for complementary products.
- Results read as percentages, e.g. “30% of people who buy frozen mutton also buy charcoal”, written as left-hand side implies right-hand side (antecedent → consequent).
- Uses: store layout, product bundling, promotions; tie-in tricks such as a sale on diapers while raising the price of milk.
Measures
| Measure | Formula | Meaning |
|---|---|---|
| Support (usefulness) | transactions containing the items / total transactions | % of baskets where the rule is true (both sides present) |
| Confidence (certainty) | support(items) / support(antecedent) | % of baskets with the left-hand item that also have the right-hand item |
| Lift (correlation) | confidence(A → B) / support(B) | How much more often A appears with B than without it. Lift < 1 means no cross-selling opportunity |
Example (measures deck, slide 11)
- 5 transactions; milk appears in 3, chip in 2, both in 2.
- support(milk & chip) = 2/5 = 0.4; confidence(milk → chip) = 0.4/0.6 = 0.67; lift = 0.67/0.4 = 1.67.
Two main processes: (1) find itemsets above the minimum support (frequent itemsets); (2) generate rules above the minimum confidence. Strong rules satisfy both.
Frequent itemset basics (7b)
- Itemset: a set of one or more items; a k-itemset has k items.
- Support count (absolute support): how often an itemset occurs. An itemset is frequent if its support is no less than the min-support threshold.
- Number of candidate k-itemsets from n items is nCk (n choose k).
Apriori (7b)
- Apriori property: any subset of a frequent itemset must be frequent (if {milk, diaper, nuts} is frequent, so is {milk, diaper}).
- Apriori pruning principle: if an itemset is infrequent, its supersets should not be generated or tested.
- A candidate generation-and-test approach (Agrawal et al., 1993). Brute force over itemsets with multiple database scans.
Generating candidates
- Self-join: join L(k−1) with itself to get candidate set Ck.
- Prune: remove any candidate with a (k−1)-subset that is not in L(k−1).
- Scan the database to count support; keep candidates meeting min-support as Lk. Repeat until no candidates are left.
- Slide example (min support 2): L2 = {AC, BC, BE, CE}. Self-join gives ABC, ACE, BCE; ABC is pruned (AB not in L2), ACE is pruned (AE not in L2), so L3 = {BCE}.
- Rules from {A, C}: A → C and C → A, each kept if its confidence meets min-confidence.
- Challenges: multiple database scans, a huge number of candidates, tedious support counting.
- Improvements: reduce scans, shrink candidates, ease support counting; partitioning (scan the database only twice); sampling.
- Tools such as Weka can find frequent patterns and visualise rule sets.
FP-Growth (7c)
Mining frequent patterns without candidate generation. Two processes: (1) construct the FP-tree, (2) mine the FP-tree. It is depth-first, divide-and-conquer, and needs only two scans of the database.
Building the FP-tree
- Scan 1: count each item's support (as in Apriori) and build the header table L in descending support order, e.g. {I2: 7, I1: 6, I3: 6, I4: 2, I5: 2}.
- Create the root, labelled “null”.
- Scan 2: sort each transaction's items in L order and add it as a branch. Where it shares a prefix with an existing path, increment those nodes' counts; create new nodes for the rest.
- The header table links each item to its occurrences in the tree (node-links).
Mining the FP-tree
- Start from the least frequent item (e.g. I5) as a suffix.
- Collect its prefix paths: the conditional pattern base, e.g. {I2, I1: 1} and {I2, I1, I3: 1} for I5.
- Build its conditional FP-tree, dropping items below min support (I3 here), e.g. ⟨I2: 2, I1: 2⟩.
- Generate patterns from the combinations: {I2, I5: 2}, {I1, I5: 2}, {I2, I1, I5: 2}. Repeat for I4, I3, I1.
| Apriori | FP-Growth | |
|---|---|---|
| Candidates | Candidate generation and test | No candidate generation |
| Search | Breadth-first, brute force | Depth-first, divide and conquer |
| Database scans | Multiple | Two |
| Structure | Candidate sets Ck and frequent sets Lk | Compressed FP-tree |
- Benefits of FP-growth: decomposes the mining task and database by frequent patterns (focused search of smaller databases); no candidate generation or test; compressed database; no repeated scans; basic operations are counting local frequent items and building sub FP-trees. It scales better than Apriori as the support threshold drops.