Skip to content

Profile the miner

FP-Growth is recursive and its runtime depends strongly on how much the transactions share prefixes. When a run is slow, profile it with the built-in cProfile module.

Profile a run

python3 -m cProfile -o data.prof -m fpgrowth -i data.txt

Then inspect the statistics:

python3 -m pstats data.prof

or visualize them with snakeviz:

python3 -m pip install snakeviz
snakeviz data.prof

What to look for

  • Recursion depth. FP-Growth recurses once per item in an itemset. Very long frequent itemsets can approach Python's recursion limit.
  • Wide conditional trees. Dense databases with many frequent items produce large conditional trees; lowering min_support increases both time and memory.
  • The initial scan. Counting item frequencies is linear in the database size and is usually not the bottleneck unless the database is very large.

Practical tips

  • Raise min_support to shrink the search space.
  • Keep transactions as sets of integers when possible; hashing small integers is cheap.
  • For very large databases, stream the file through read_transactions rather than keeping many copies of the same data.