FP-Growth algorithm for association rule mining.
Classes
FP-Tree data structure for efficient frequent pattern mining.
__init__( self, )
Methods
__init__
(self)
FP-Growth algorithm for association rule mining.
__init__( self, min_support: float = 0.1, min_confidence: float = 0.8, max_itemset_size: Optional[int] = None, )
Overview
The algorithm operates in two main phases:
- FP-tree construction: Scan the database once to find frequent 1-itemsets, then scan again to insert each transaction (sorted by descending frequency) into the FP-tree
- For each item in ascending frequency order, extract its conditional pattern base (prefix paths ending at nodes for that item)
- Build a conditional FP-tree from the conditional pattern base
- Recursively mine the conditional FP-tree to discover longer frequent patterns
- Combine prefix patterns to form all frequent itemsets
- Generate association rules from the complete set of frequent itemsets
Theory
The FP-tree achieves compression by sharing common prefixes among transactions. A header table links all nodes for the same item, enabling efficient traversal.
For an itemset X, the support is obtained from the FP-tree as:
where \text{count}(X) is derived from the conditional pattern base of the least frequent item in X.
Confidence and Lift for a rule A \Rightarrow C:
The FP-tree completeness theorem guarantees that the FP-tree contains all information needed for mining frequent patterns, with no information loss compared to the original database.
Parameters
min_support
min_confidence
max_itemset_size
Attributes
frequent_itemsets_
rules_
n_transactions_
fit.
n_items_
Notes
Complexity:
- FP-tree construction: O(n \cdot m) where n = number of transactions and m = average transaction length
- Space: O(n \cdot m) worst case for the FP-tree, but typically much smaller due to prefix sharing
- Mining: depends on the tree structure; highly compressed trees lead to faster mining
- Large datasets where Apriori's multiple database scans are prohibitive
- When the transaction database has many shared prefixes (high compression)
- Dense datasets with many frequent items
- When you want to avoid candidate generation overhead entirely
References
See Also
Basic usage for discovering association rules from transaction data:
>>> from tuiml.algorithms.associations import FPGrowthAssociator
>>> transactions = [['milk', 'bread', 'butter'], ['beer', 'diapers'],
... ['milk', 'diapers', 'beer', 'cola'], ['bread', 'milk', 'diapers', 'beer']]
>>> model = FPGrowthAssociator(min_support=0.5, min_confidence=0.7)
>>> model.fit(transactions)
FPGrowthAssociator(n_itemsets=11, n_rules=18, min_support=0.5)
Methods
fit
(self, X) -> 'FPGrowthAssociator'
fit
(self, X) -> 'FPGrowthAssociator'
Find frequent itemsets and generate association rules.
Parameters
X
Returns
self