Skip to content

Commit

Permalink
Fix asaini#11, asaini#13 and asaini#20 and add Python3 support tp apr…
Browse files Browse the repository at this point in the history
…iori script.
  • Loading branch information
muety committed Oct 3, 2018
1 parent 804020f commit c240f2a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions apriori.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def getSupport(item):
for item in value])

toRetRules = []
for key, value in largeSet.items()[1:]:
for key, value in list(largeSet.items())[1:]:
for item in value:
_subsets = map(frozenset, [x for x in subsets(item)])
for element in _subsets:
Expand All @@ -115,21 +115,21 @@ def getSupport(item):

def printResults(items, rules):
"""prints the generated itemsets sorted by support and the confidence rules sorted by confidence"""
for item, support in sorted(items, key=lambda (item, support): support):
print "item: %s , %.3f" % (str(item), support)
print "\n------------------------ RULES:"
for rule, confidence in sorted(rules, key=lambda (rule, confidence): confidence):
for item, support in sorted(items, key=lambda x: x[1]):
print("item: %s , %.3f" % (str(item), support))
print("\n------------------------ RULES:")
for rule, confidence in sorted(rules, key=lambda x: x[1]):
pre, post = rule
print "Rule: %s ==> %s , %.3f" % (str(pre), str(post), confidence)
print("Rule: %s ==> %s , %.3f" % (str(pre), str(post), confidence))


def dataFromFile(fname):
"""Function which reads from the file and yields a generator"""
file_iter = open(fname, 'rU')
for line in file_iter:
line = line.strip().rstrip(',') # Remove trailing comma
record = frozenset(line.split(','))
yield record
with open(fname, 'rU') as file_iter:
for line in file_iter:
line = line.strip().rstrip(',') # Remove trailing comma
record = frozenset(line.split(','))
yield record


if __name__ == "__main__":
Expand Down Expand Up @@ -158,7 +158,7 @@ def dataFromFile(fname):
elif options.input is not None:
inFile = dataFromFile(options.input)
else:
print 'No dataset filename specified, system with exit\n'
print('No dataset filename specified, system with exit\n')
sys.exit('System will exit')

minSupport = options.minS
Expand Down

0 comments on commit c240f2a

Please sign in to comment.