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¶
Then inspect the statistics:
or visualize them with snakeviz:
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_supportincreases 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_supportto 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_transactionsrather than keeping many copies of the same data.