Mining frequent itemsets using the apriori algorithm
Code: "mining_alg_fi1.py". Programming language: Python
DMelt Version 1. Last modified: 12/08/2015. License: Pro
https://datamelt.org/code/cache/mining_alg_fi1_5624.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.
"""
Apriori is an algorithm for discovering frequent itemsets in transaction databases. It was proposed by Agrawal & Srikant (1993).
Apriori is an algorithm for discovering itemsets (group of items) occurring frequently in a transaction database (frequent itemsets). A frequent itemset is an itemset appearing in at least minsup transactions from the transaction database, where minsup is a parameter given by the user.
"""
from ca.pfv.spmf.algorithms.frequentpatterns.apriori import AlgoApriori
from ca.pfv.spmf.patterns.itemset_array_integers_with_count import Itemsets
# 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=AlgoApriori()
alg.runAlgorithm(0.4,"data.txt",out)
# alg.printStats()
print "result="
print open(out).read()
You see the box below because you did not login.