Mine all association rules with FPGROWTH
Code: "mining_alg_association.py". Programming language: Python
DMelt Version 1. Last modified: 12/08/2015. License: Pro
https://datamelt.org/code/cache/mining_alg_association_5325.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.
from ca.pfv.spmf.algorithms.associationrules.agrawal94_association_rules import AlgoAgrawalFaster94;
from ca.pfv.spmf.algorithms.associationrules.agrawal94_association_rules import AssocRules;
from ca.pfv.spmf.algorithms.frequentpatterns.fpgrowth import AlgoFPGrowth;
from ca.pfv.spmf.patterns.itemset_array_integers_with_count import Itemsets;
# create input data
data="""1 2 4 5
2 3 5
1 2 4 5
1 2 3 5
1 2 3 4 5
2 3 4
"""
file = open("data.txt", "w")
file.write(data)
file.close()
# use 0.4: means a minsup of 2 transaction (we used a relative support)
print "Step 1: Applying the FP-GROWTH algorithm to find frequent itemsets"
alg=AlgoFPGrowth()
patterns=alg.runAlgorithm("data.txt",None,0.5)
databaseSize = alg.getDatabaseSize();
out="output.txt"
print "Step 2: Generating all rules from the set of frequent itemsets (based on Agrawal & Srikant, 94)"
algoAgrawal = AlgoAgrawalFaster94();
rules=algoAgrawal.runAlgorithm(patterns,out,databaseSize, 0.6)
print "result="
print open(out).read()
You see the box below because you did not login.