skip to content

How does FP-growth mine frequent itemsets without generating candidates?

level: middleimportance: nice to knowfreq 30%

answer

  1. compress the log, then mine it
  2. two scans, not one per length
  3. shared prefixes share nodes
  4. conditional pattern base per item
  5. memory blows up on sparse data

basics

~20 s

It compresses the transactions into a prefix tree in two passes, then mines recursively from conditional sub-trees built for each item. No candidate itemsets are enumerated and no extra pass over the raw data is needed per itemset length.

solid answer

~50 s

FP-growth replaces candidate generation with a compressed representation of the data. The first pass counts single items, drops the infrequent ones and orders the survivors by descending frequency. The second pass inserts each basket's surviving items, in that order, as a path in a prefix tree, so baskets sharing a leading run of popular items share nodes and increment their counts. A header table chains together all nodes for each item. Mining then works item by item from the least frequent upward: follow an item's node chain to collect its conditional pattern base - the prefix paths that co-occur with it - build a smaller conditional tree from those, and recurse. Over ten million baskets this is two scans instead of one per itemset length. The trade is memory: if baskets share few prefixes the tree barely compresses and may not fit.

go deeper

for a junior

Know that there is a second family of frequent-itemset algorithms that compresses the transactions into a tree and avoids enumerating candidates. The name and the one-line idea are enough here.

for a middle

Be able to describe both scans, why items are ordered by descending frequency, and what a conditional pattern base is. Compare the two-scan cost against a pass per itemset length.

for a senior

Show you know when the compression fails - sparse wide baskets, very low thresholds - and what you do then: partition and merge, raise the threshold, or fall back to the level-wise method whose memory is predictable.

for a principal

Treat this as a capacity decision. The choice between the two families is really a choice between input/output cost and memory ceiling on your cluster, and it should be revisited when the catalogue or the threshold policy changes.

## The idea Apriori pays for its simplicity twice: it enumerates candidate itemsets, and it re-reads the transaction log once per itemset length. FP-growth removes both costs by first squeezing the log into an in-memory structure that preserves exactly the information support counting needs, then mining that structure recursively. ## Building the tree - two scans **Scan one.** Count every item. Discard everything below the minimum support - by downward closure, no itemset containing a dropped item can be frequent, so removing them now is lossless. Sort the survivors by descending frequency; call this the item order. **Scan two.** For each basket, keep only the frequent items and sort them into the global item order. Insert that sequence as a path from the root of the tree, creating nodes where needed and incrementing a count on every node reused. Sorting by descending frequency is deliberate: the most common items sit near the root, so the maximum number of baskets share the same prefix nodes, which is where the compression comes from. Alongside the tree, a **header table** holds one entry per frequent item with its total count and the head of a linked list threading every node for that item, wherever it sits in the tree. Over ten million supermarket baskets drawn from a catalogue where a few hundred items dominate, this collapses dramatically: millions of baskets funnel through the same handful of top-level nodes. The tree, not the log, is what the rest of the algorithm reads. ## Mining - conditional pattern bases Mining proceeds item by item, starting from the *least* frequent item in the header table and working up. 1. Follow the item's node chain. For each node, walk up to the root to read the prefix path, and tag that path with the node's count. The collection of these counted paths is the item's **conditional pattern base** - literally, the baskets that contained this item, projected onto the items that come before it in the ordering. 2. Treat the conditional pattern base as a small transaction database of its own, drop items in it that now fall below the threshold, and build a **conditional FP-tree** from it. 3. Recurse on that conditional tree, accumulating the item into the growing pattern prefix. Each recursion works on strictly fewer items over strictly smaller data, and every itemset it emits is frequent by construction. Nothing is ever proposed and then tested, which is the sense in which the method is candidate-free: it grows patterns out of the data rather than generating them from the previous level. ## Cost profile against level-wise mining - **Data scans.** Two, versus roughly one per itemset length. When the log is large and disk-resident, or long frequent itemsets exist, this is the dominant win. - **Candidate enumeration.** None, versus a join-and-prune step per level whose candidate set can be enormous at low thresholds. - **Memory.** The whole compressed tree, plus a stack of conditional trees during recursion, must fit. Level-wise mining only needs the current candidate set and its counters. The memory point is the real failure mode. Compression depends on baskets sharing prefixes. Data that is wide and sparse - many items, short baskets, little overlap in what people buy - produces a tree with almost as many nodes as there are item occurrences, plus per-node overhead, and it can be *larger* than the input. Very low support thresholds have the same effect, because few items get filtered out in scan one and the ordering has less mass at the top. When the tree will not fit, the usual answers are to partition the transactions, mine each partition and merge, or to raise the threshold. ## What it does not change FP-growth is a different route to the same destination: the set of frequent itemsets at a given minimum support, with exact counts. It does not alter which itemsets are frequent, does not produce different support values, and does not generate rules - rule generation from frequent itemsets, with its own confidence threshold, is a separate phase either way. Nor does it remove the redundancy in the output; closed or maximal representations are still the answer when the itemset list itself is too large. ## In an interview The expected shape of the answer is: compress into a prefix tree in two scans, exploit shared prefixes, mine recursively via conditional pattern bases, no candidates. The differentiating sentence is the caveat - the compression is data-dependent, and on sparse data with a low threshold the tree can blow memory, which is precisely when the level-wise alternative, slow but predictable in memory, is preferable.

  • Why are items sorted by descending frequency before insertion into the tree?
    Because the compression comes entirely from shared prefixes. Putting the most common items nearest the root maximises how many baskets travel down the same nodes before diverging, which shrinks the tree. A different ordering still produces correct results - support counts are unaffected - but the structure can be far larger, and a larger tree is the one thing that makes this method fail.
  • When would you prefer level-wise Apriori mining over FP-growth?
    When memory is the binding constraint rather than input/output. Apriori holds only the current candidate set and its counters, so its footprint is predictable and it degrades gracefully on wide sparse data where a prefix tree barely compresses. It also partitions naturally across machines by splitting transactions and merging counts, and with a high support threshold the handful of extra passes costs little.
  • Does FP-growth change which itemsets come out as frequent?
    No. At the same minimum support both methods return exactly the same frequent itemsets with the same support counts; only the route differs. That makes the choice purely an engineering one about scans versus memory. It also means neither method produces rules - splitting frequent itemsets into antecedent and consequent and applying a confidence threshold is a separate phase run afterwards.

Instead of guessing which combinations might be common and checking each guess against the whole log, FP-growth files the log into a shared-prefix filing cabinet once, then reads the answers off the folders.

saying these in an interview costs you the question

  • Says FP-growth needs no pass over the data at all
  • Claims the prefix tree always compresses the transactions
  • Thinks the two methods return different frequent itemsets
  • Describes FP-growth as generating and testing candidates
  • Ignores that the tree must fit in memory

context