Frequent Pattern Mining (Basic)
Motivation and Definitions
Frequent patterns: itemsets, subsequences, or substructures that appear together (or in sequence) frequently in a data set.
- Market basket analysis: find items bought together to design placement, promotions, and recommendation.
- Interesting not only in retail — also web logs, bio-sequences, program flows.
Basic Concepts (Itemset)
- Itemset: a set of items, e.g.,
. -itemset: an itemset containing items. - Support count (
) / absolute support: number of transactions containing the itemset. - Support (relative):
fraction of transactions containing . - Frequent itemset: an itemset whose support
user-specified minimum support threshold, . -frequent: frequent -itemset.
Association Rules
A rule
- Support:
- Confidence:
- Frequent rule: support
(both and frequent). - Confident rule: confidence
.
Example: {milk, diaper} → {beer} with
Correlation / Lift
Support & confidence alone can be misleading (a rule can have high confidence simply because
: and independent (no correlation). : positively correlated (co-occur more than chance). : negatively correlated. Also and all_confidence / cosine can measure correlation.
The Apriori Algorithm (Itemset Mining)
Downward closure / Apriori property: any subset of a frequent itemset must itself be frequent. Equivalently, any superset of an infrequent itemset is infrequent — used for pruning.
Intuition
- Enumerate itemsets level-by-level:
- Use frequent
-itemsets to generate candidate -itemsets, then prune candidates whose -subsets are not frequent.
Algorithm Steps
L1 = { frequent 1-itemsets };
for (k = 2; L_{k-1} ≠ ∅; k++) {
Ck = apriori_gen(L_{k-1}, minsup); // candidate generation + pruning
for each transaction t in DB {
Ct = subset(Ck, t); // candidates contained in t
for each c in Ct: c.count++;
}
Lk = { c in Ck | c.count/|T| ≥ minsup };
}
return ∪k Lk;apriori_gen (Candidate Generation + Pruning)
- Join step: for each pair
that agree on first items, differ only in the last item, produce candidate . - Prune step: delete any candidate
if any -subset of is not in .
Example (minsup = 50%, |T|=4)
Suppose transactions yield
Rule Generation from Frequent Itemsets
For each frequent itemset
Can also prune using the rule anti-monotone property: if
Complexity and Bottlenecks of Apriori
- Bottleneck 1: candidate generation — huge number of candidates (esp.
). Number of maximal candidates combinations. - Bottleneck 2: multiple DB scans (one per
). For dense / long patterns this is expensive. - Bottleneck 3: support counting for each candidate against each transaction.
Worst-case itemset count
Improvements / Variations
- PCY (Park-Chen-Yu): hash candidate pairs into buckets during
pass; mark frequent buckets to prune . - Multistage / Multihash: multiple hash passes to better prune.
- Partition: two scans — any globally frequent itemset must be frequent in at least one partition ⇒ prune candidates early.
- Sampling: mine a sample, verify on full DB; risky (false positives/negatives).
- DIC (Dynamic Itemset Counting): count candidates earlier as soon as supported.
- Trade (vertical format / tid-lists): represent items by transaction-id lists; intersect lists to count — avoids candidate explosion for some data.
Closed and Maximal Patterns (preview, see Ch.6)
- Many frequent itemsets are redundant (
frequent implies frequent). We often want closed and maximal frequent itemsets to compress representation.
Worked Apriori Example (Concrete Counts)
Transactions (minsup = 50%, so min count = 2 with |T|=4):
| TID | Items |
|---|---|
| T1 | A, B, C |
| T2 | A, B, D |
| T3 | B, C, D |
| T4 | A, C, D |
(count ≥ 2): A(3), B(3), C(3), D(3). from joins: AB(2), AC(3), AD(3), BC(2), BD(2), CD(3) → = all (each ≥ 2). (join pairs sharing 2 prefix items): ABC, ABD, ACD, BCD. Prune by apriori property: all 3-subsets of each are in , so none pruned. - Counts: ABC(1), ABD(2), ACD(2), BCD(2). With min count 2 ⇒
= {ABD, ACD, BCD}. = ABCD? Its 3-subsets include ABC (count 1 ∉ ) ⇒ pruned. Stop.
Frequent itemsets = all of
Rule Generation Example
From frequent
: . : . : . : . Keep rules with (say 60%). Anti-monotone pruning: if fails, then any rule with antecedent (e.g., ) also fails — prune without counting.
Support, Confidence, Lift — Full Example
For
More on Improvements
- DIC (Dynamic Itemset Counting): begins counting a candidate as soon as all its subsets can possibly be frequent (before fully finishing earlier levels) — reduces passes over the DB.
- Sampling: pick a sample, find frequent itemsets there, then verify on full data; adds a "negative border" check to catch false negatives. Risk: may miss some frequent sets (acceptable for approximate mining).
- Vertical (tid-list) format: store for each item the list of TIDs containing it; support of a set = size of the intersection of tid-lists. Avoids repeated transaction scans (leads to ECLAT, Ch. 6).
Beyond Lift: Other Interestingness Measures
- Conviction:
; when perfectly confident, 1 when independent. - Leverage (Piatetsky):
— absolute deviation from independence. - Collective strength / J-measure: information-theoretic surprise of the rule. These rank rules when support/confidence alone mislead (a rule can be confident merely because the consequent is frequent).
Parallel & Scalable Apriori
- Count distribution: each processor scans a data partition and ships local counts; master sums (uses the partitioning idea).
- Data distribution: broadcast candidates, each node counts its shard.
- MapReduce: mappers emit candidate subsets per transaction, reducers aggregate — natural fit for the
counting step.
Why the Support Threshold Matters
- Too high → miss rare but interesting patterns (e.g., fraud combos).
- Too low → combinatorial explosion of candidates (the Apriori bottleneck).
- Practical fixes: top-
frequent patterns (specify instead of ) or constraint-based mining (only items of interest).
Limitations of Association Rules
- They capture correlation, not causation.
- Redundant rules explode as itemsets grow (mitigated by closed/maximal, Ch. 6).
- Sensitive to the choice of
/ and data skew.
Apriori Candidate Generation — Detail
The join step enumerates
Apriori vs FP-Growth (Comparison)
| Aspect | Apriori | FP-Growth |
|---|---|---|
| Candidate generation | yes (huge | no |
| DB scans | one per | 2 (build + mine) |
| Memory | low | tree (can be large) |
| Best for | short / sparse patterns | long / dense patterns |
| Output | all frequent itemsets | all frequent itemsets |
Rule Templates & Constraints (Practical)
Real miners rarely want all rules. Use constraints to focus:
- Item constraints: only rules containing
milk(monotone w.r.t. supersets containing it). - Aggregate constraints:
avg(price) < 10. - Class-based / meta-rule:
buys(X, "camera") → buys(X, "SD-card"). Pushing constraints into candidate generation prunes the search early (see Ch.6 constrained mining).
Summary
Frequent pattern mining finds itemsets whose support exceeds