Mining frequent itemsets using the FP-Growth Algorithm
Code: "mining_alg_fi2.py". Programming language: Python
DMelt Version 1. Last modified: 12/08/2015. License: Pro
https://datamelt.org/code/cache/mining_alg_fi2_5261.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
# FPGrowth is an algorithm for discovering frequent itemsets in a transaction database. It was proposed by Han et al. (2000). FPGrowth is a very fast and memory efficient algorithm. It uses a special internal structure called an FP-Tree.
from ca.pfv.spmf.algorithms.frequentpatterns.fpgrowth import AlgoFPGrowth;
# create input data
data="""1 3 4
2 3 5
1 2 3 5
2 5
1 2 3 5
"""
file = open("data.txt", "w")
file.write(data)
file.close()
# use 0.4: means a minsup of 2 transaction (we used a relative support)
out="output.txt"
alg=AlgoFPGrowth()
alg.runAlgorithm("data.txt",out,0.4)
# alg.printStats()
print "result="
print open(out).read()
You see the box below because you did not login.