print('Number of frequent {}-itemsets: {}.'.format(k, len(tidlists[k]))) k += 1 out = open(sys.argv[4], 'w') # Print results out.write('itemsets\n') for i inrange(1, k): #print('Frequent {}-itemsets'.format(i)) for (itemset, tidlist) in tidlists[i].items(): out.write(' '.join(itemset1) + '\n') out.write(str(len(tidlist)/transactions) + '\n')
out.write('rules\n') for i inrange(1, k): #print('Frequent {}-itemsets'.format(i)) for (itemset, tidlist) in tidlists[i].items(): subsets = [] for j inrange(1, len(itemset)): subsets = subsets + list(itertools.combinations(itemset, j))
for subset in subsets: difference = set(itemset).difference(subset) confidence = len(tidlist)/len(tidlists[len(subset)][tuple(subset)]) if confidence < min_conf: continue out.write(' '.join(subset) + '\n') out.write(' '.join(difference) + '\n') out.write(str(confidence) + '\n')