Skip to main content
MahiDev — Learn. Build. Become AI-ready.

Lesson 51

FP-Growth

Compress transactions into a frequency tree and read co-occurrence from that tree instead of listing every candidate pair.

Intermediate12 min
FP-Growth MahiDev

What You Will Learn

  • Idea
  • Example
  • When to use it

Idea

FP-Growth stores the baskets in a tree of frequent items. To study one item, it collects only the branches that contain that item. Those branches are the conditional pattern base. Counting inside that smaller set replaces Apriori's repeated full scans.

Example

python
baskets = [
    {"bread", "milk"},
    {"bread", "diaper", "beer"},
    {"milk", "diaper", "beer", "cola"},
    {"bread", "milk", "diaper", "beer"},
    {"bread", "milk", "diaper", "cola"},
]
bases = [basket - {"diaper"} for basket in baskets if "diaper" in basket]
beer = sum("beer" in base for base in bases)
print(f"baskets with diaper: {len(bases)}")
print(f"beer beside diaper: {beer}")

Output:

text
baskets with diaper: 4
beer beside diaper: 3

When to use it

  • Use it when the transaction list is large and Apriori's candidate pairs get expensive.
  • The counts above are the conditional pattern for diaper, not a full rule list.
  • You still set a minimum support. The tree only changes how the count is done.

Loading playground…