Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Compress first, then count
Apriori counts a growing list of guesses, scanning all the receipts again and again. FP-Growth first squeezes all the receipts into one compact tree. Each receipt becomes a path from the root, with the most popular items first, so receipts that start the same way share the same branch, and a counter on each node records how many receipts pass through. Then it reads every frequent combination out of that tree, never going back to the raw data.
Large maintenance databases, alarm logs and clickstreams make Apriori’s repeated scans and candidate floods impractical at the low supports where interesting patterns live. FP-Growth (and its parallel version in Spark MLlib) is the standard workhorse for frequent pattern mining at scale.
- 1. FP-Growth avoids…
- 2. In an FP-tree, receipts that start with the same items…
- 3. How many passes over the raw data does FP-Growth need?
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Building and reading the tree by hand
Step 1: count. In the demo’s ten transactions with a minimum count of 3, the frequent items are c:8, f:8, m:7, a:6, p:6, b:5. All other items are dropped.
Step 2: insert. Sort each transaction’s frequent items by descending count (ties alphabetically) and insert the sorted list as a path, incrementing counts on shared nodes.
- The first transaction becomes c f m a p.
- The ten transactions hold 40 frequent-item occurrences but need only 14 nodes.
Step 3: node-links. For each item, keep a chain through all of its nodes. The header table points to the start of each chain.
Step 4: conditional pattern base. For item m, follow its node-links and read each node’s prefix path with that node’s count: “c f” (×6) and “f” (×1). All frequent itemsets ending in m live in this base.
Step 5: recurse.
- Count items in the base: c:6, f:7. Build its tiny conditional tree, and mine the itemsets ending in m: m, fm, cm and cfm, all with count ≥ 3.
- When a conditional tree is a single path of m items, all 2^m − 1 combinations are frequent and can be listed directly.
The steps in plain English:
- Scan once: count items and keep the frequent ones.
- Scan again: insert each transaction’s frequent items, in descending frequency order, into the FP-tree.
- For each item, from least to most frequent, build its conditional pattern base and conditional tree, record the pattern, and recurse.
- Generate rules from the frequent itemsets exactly as with Apriori.
- 1. Items are inserted in order of…
- 2. A conditional pattern base consists of…
- 3. A single-path conditional tree of m items yields…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.Compression, ordering and work
Why descending order? Frequent items appear in many transactions. Placing them near the root makes long shared prefixes, so most transactions reuse existing nodes. Reverse order puts rare items at the top, where few transactions share them, and the tree branches early.
Correctness. Every transaction’s frequent items are stored along exactly one root-to-node path. The paths above all nodes of item i, with their counts, contain exactly the co-occurrence counts of i with the items before it in the ordering. Recursing on these bases enumerates each frequent itemset once, at its least frequent item.
Work. FP-Growth never counts infrequent candidates. Its cost is building and traversing conditional trees, which can still be large when there are very many frequent patterns, and it needs the tree in memory. Apriori’s cost is subset testing for every candidate against every transaction, at every level.
Exercise 1 (500 baskets over 20 items, minimum count 25):
- FP-Growth found 50 frequent itemsets, identical to level-wise counting;
- the FP-tree had 673 nodes for 1753 item occurrences, 2.6× compression, built in two data scans.
from mlxtend.frequent_patterns import fpgrowth
freq = fpgrowth(onehot_df, min_support=0.02, use_colnames=True)
# Spark: pyspark.ml.fpm.FPGrowth(itemsCol="items", minSupport=0.02, minConfidence=0.5)- 1. Each frequent itemset is generated once, at its…
- 2. FP-Growth's main resource cost is…
- 3. Reverse frequency order makes the FP-tree…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Complexity. The FP-tree has at most as many nodes as there are frequent-item occurrences, and usually far fewer on correlated data. Mining time is roughly proportional to the total size of all conditional trees, which grows with the number of frequent itemsets: output-sensitive, unlike Apriori, whose cost also includes infrequent candidates.
Item-ordering heuristic. Finding the order that minimises the FP-tree size is a hard combinatorial problem. Descending support is a good heuristic because it maximises expected prefix sharing under independence, but it is not always optimal.
Variants.
- PFP (Li et al., 2008) partitions items across machines, each mining conditional bases for its group: Spark MLlib’s FPGrowth.
- FP-Max and FP-Close mine maximal and closed itemsets.
- Tree projection and H-mine trade memory for speed.
- Sampling and streaming versions approximate frequencies with guarantees.
Interview questions.
- When is FP-Growth slower than Apriori? On very sparse data with high support, where the tree barely compresses and Apriori has few candidates, and when the tree does not fit in memory.
- How does FP-Growth scale to a cluster? Partition by item groups (PFP): each worker receives the transactions relevant to its group’s conditional bases and mines them independently.
- 1. FP-Growth's mining cost is…
- 2. Spark's FPGrowth parallelises by…
- 3. Is descending frequency always the smallest-tree order?
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.How much does ordering and avoiding candidates save?
History.
- J. Han, J. Pei and Y. Yin (2000) introduced FP-Growth.
- J. Pei, J. Han and R. Mao (2000) introduced CLOSET for closed patterns.
- G. Grahne and J. Zhu (2005) introduced FP-Max and FPclose.
- H. Li et al. (2008) introduced PFP, the parallel FP-Growth in Spark.
Exercise 2. A sparse dataset (1500 baskets, 80 Zipf-distributed items, minimum count 15) and a dense one (600 correlated baskets over 16 popular items, minimum count 150).
| sparse | dense | |
|---|---|---|
| item occurrences | 3447 | 5438 |
| FP-tree nodes, descending order | 1318 | 1768 |
| FP-tree nodes, random order | 1529 | 2254 |
| FP-tree nodes, ascending order | 1704 | 2930 |
| FP-Growth: nodes built in all trees | 1372 | 3998 |
| Apriori: subset tests | 3 669 000 | 369 000 |
| Apriori: data scans | 3 | 5 |
| frequent itemsets (both) | 99 | 316 |
- Descending frequency order gave the smallest trees, 23% fewer nodes than ascending order on sparse data and 40% fewer on dense data, with random order in between.
- On sparse data the tree barely compressed (3447 occurrences into 1318 nodes), yet FP-Growth still avoided Apriori’s 3.7 million subset tests: Apriori had to test 2446 candidate itemsets against all 1500 baskets.
- On dense data the conditional trees did more of the work (3998 nodes in total), reflecting more frequent patterns, while Apriori needed 5 scans for patterns up to size 5.
- Both returned identical itemsets: FP-Growth changes the cost, not the answer.
FP-Growth in AI, robotics and aerospace
- Fleet maintenance mining: frequent fault-code combinations across millions of work orders, with Spark FPGrowth.
- Telemetry event patterns: co-occurring discrete events (mode changes, warnings) within flight segments, after discretising the windows into transactions.
- Feature-interaction discovery: frequent combinations of binarised conditions that precede failures, as candidate rules for monitoring.
References
- J. Han, J. Pei, Y. Yin (2000). “Mining frequent patterns without candidate generation.” Proc. ACM SIGMOD.
- J. Han, J. Pei, Y. Yin, R. Mao (2004). “Mining frequent patterns without candidate generation: a frequent-pattern tree approach.” Data Mining and Knowledge Discovery 8(1).
- H. Li, Y. Wang, D. Zhang, M. Zhang, E. Y. Chang (2008). “PFP: parallel FP-growth for query recommendation.” Proc. ACM RecSys.
- G. Grahne, J. Zhu (2005). “Fast algorithms for frequent itemset mining using FP-trees.” IEEE Transactions on Knowledge and Data Engineering 17(10).