Skip to content

fpgrowth

A dependency-free, pure-Python implementation of the FP-Growth algorithm for mining frequent itemsets from a transaction database.

FP-Growth (frequent pattern growth) discovers every itemset whose support meets a threshold without the candidate-generation step used by Apriori. It builds a compressed prefix tree — the FP-tree — and mines it recursively.

Features

  • Standard library only. No third-party packages are required at runtime.
  • Two interfaces. A fpgrowth command-line tool and an importable Python API.
  • Correct by construction. The test suite compares the miner against an independent brute-force oracle over randomized databases.
  • Deterministic. The same input always produces the same output ordering.

Where to start

This documentation follows the Diátaxis framework, so each section serves a different need:

A thirty-second example

from fpgrowth import mine_frequent_itemsets

transactions = [
    {1, 3, 4},
    {2, 3, 5},
    {1, 2, 3, 5},
    {2, 5},
]

patterns = mine_frequent_itemsets(transactions, min_support=0.5)
for itemset, support in sorted(patterns.items(), key=lambda kv: (len(kv[0]), sorted(kv[0]))):
    print(sorted(itemset), support)

License

Released under the GNU General Public License v3.0. See LICENSE.