Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2755444

Browse files
author
Eric Naeseth
committed
Make the fp_growth module executable in a useful default state.
1 parent bb816ca commit 2755444

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

fp_growth.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,23 @@ def __repr__(self):
357357
return "<%s (root)>" % type(self).__name__
358358
return "<%s %r (%r)>" % (type(self).__name__, self.item, self.count)
359359

360+
361+
if __name__ == '__main__':
362+
from optparse import OptionParser
363+
import csv
364+
365+
p = OptionParser(usage='%prog data_file')
366+
p.add_option('-s', '--minimum-support', dest='minsup', type='int',
367+
help='Minimum itemset support (default: 2)')
368+
p.set_defaults(minsup=2)
369+
370+
options, args = p.parse_args()
371+
if len(args) < 1:
372+
p.error('must provide the path to a CSV file to read')
373+
374+
f = open(args[0])
375+
try:
376+
for itemset in find_frequent_itemsets(csv.reader(f), options.minsup):
377+
print '{' + ', '.join(itemset) + '}'
378+
finally:
379+
f.close()

0 commit comments

Comments
 (0)