Foundations to Frontier
Tests
D. Classical Machine Learning › D12 Association Rule Mining

FP-Growth

FP-Growth (Han, Pei and Yin, 2000) finds the same frequent itemsets as Apriori without generating candidates. It scans the data twice: once to count items, then again to insert every transaction, with infrequent items removed and the rest sorted by descending frequency, as a path into a prefix tree, the FP-tree. Shared prefixes share nodes, so the tree compresses the database, and node-links chain together all nodes of each item. Mining works by divide and conquer: for each item, collect the prefix paths above its nodes, its conditional pattern base, build a small conditional FP-tree from them, and recurse, emitting patterns directly when a conditional tree is a single path. FP-Growth is usually much faster than Apriori on dense data or at low support, at the cost of memory for the tree and a more intricate implementation. This page covers FP-tree construction and its compression, the item-ordering heuristic, conditional pattern bases and recursive mining, correctness, complexity and memory, and parallel variants. In the exercises you implement FP-Growth and verify it against level-wise counting; then you measure how item ordering changes the tree size and compare the work done by Apriori and FP-Growth.

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.

FP-tree: compress the transactions, then mine conditional bases
p:3b:1a:5b:1m:6f:6b:2p:2c:8b:1p:1a:1m:1f:2∅
frequent items (count): c:8, f:8, m:7, a:6, p:6, b:5 · tree nodes 14 for 40 item occurrences
conditional pattern base of m: c f (×6) · f (×1)
The first five transactions are the classic example from Han, Pei and Yin's FP-Growth paper; five more were added. Ordering items by descending frequency puts the common items near the root, where many transactions share them, so the tree is smallest. Ascending order shares little and the tree balloons. The highlighted nodes are the chosen item's node-link chain; the paths above them, with their counts, form the conditional pattern base, from which all frequent itemsets ending in that item are mined.
Why engineers care

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.

📝 Quick check (Level 0)
0/3 answered
  1. 1. FP-Growth avoids…
  2. 2. In an FP-tree, receipts that start with the same items…
  3. 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:

  1. Scan once: count items and keep the frequent ones.
  2. Scan again: insert each transaction’s frequent items, in descending frequency order, into the FP-tree.
  3. For each item, from least to most frequent, build its conditional pattern base and conditional tree, record the pattern, and recurse.
  4. Generate rules from the frequent itemsets exactly as with Apriori.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Items are inserted in order of…
  2. 2. A conditional pattern base consists of…
  3. 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)
🐍 Exercise 1: FP-Growth from scratch
Build the FP-tree with a header table and node-links, mine conditional pattern bases recursively, and check that the frequent itemsets match level-wise counting; report the tree's compression.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Each frequent itemset is generated once, at its…
  2. 2. FP-Growth's main resource cost is…
  3. 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.
📝 Quick check (Level 3)
0/3 answered
  1. 1. FP-Growth's mining cost is…
  2. 2. Spark's FPGrowth parallelises by…
  3. 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.
🐍 Exercise 2 (research): ordering and work
On sparse and dense synthetic baskets, compare FP-tree sizes for descending, random and ascending item orders, and compare FP-Growth's total conditional-tree nodes with Apriori's subset tests and scans.

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

  1. J. Han, J. Pei, Y. Yin (2000). “Mining frequent patterns without candidate generation.” Proc. ACM SIGMOD.
  2. 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).
  3. H. Li, Y. Wang, D. Zhang, M. Zhang, E. Y. Chang (2008). “PFP: parallel FP-growth for query recommendation.” Proc. ACM RecSys.
  4. G. Grahne, J. Zhu (2005). “Fast algorithms for frequent itemset mining using FP-trees.” IEEE Transactions on Knowledge and Data Engineering 17(10).