NICT Club Blogs.

FP Growth Algorithm

Sudeep Mishra PP
Sudeep Mishra

The FP-Growth algorithm is a data mining technique for discovering frequent patterns in large datasets, particularly useful for association rule mining. It uses a compact structure called an FP-Tree to represent frequent items efficiently. The algorithm constructs this tree, mines it for frequent patterns recursively, and generates association rules. FP-Growth is known for its efficiency in handling large datasets compared to traditional methods like Apriori.

Source code:

# Sample code to do FP-Growth in Python

import pyfpgrowth

# Creating Sample Transactions

transactions = [

['Milk', 'Bread', 'Saffron'],

['Milk', 'Saffron'],

['Bread', 'Saffron','Wafer'],

['Bread','Wafer'],

]

#Finding the frequent patterns with min support threshold=0.5

print("Generating rules with min confidence threshold=0.5")

FrequentPatterns=pyfpgrowth.find_frequent_patterns(transactions=transactions,support_threshold=0.5)

print(FrequentPatterns)

# Generating rules with min confidence threshold=0.8

print("Generating rules with min confidence threshold=0.8")

Rules=pyfpgrowth.generate_association_rules(patterns=FrequentPatterns,confidence_threshold=0.8)

print(Rules)


More Stories