Exemple #1
0
def main():
   # PARSE ARGS
   data_filename = None
   min_sup = None
   min_conf = None
   arg_parser = lab6.get_association_args()
   args = arg_parser.parse_args()
   data_filename = args.csv_filename
   min_sup = args.min_sup
   min_conf = args.min_conf
   # BUILD GOODS DB
   beers_db = BeerDB('beers.csv')
   # BUILD BASKETS
   transactions = MarketBasketTransactions(data_filename)
   # CALC ASSOCIATIONS
   apriori = Apriori()
   frequent, rules = apriori.get_associations(transactions, min_sup, min_conf)
   outfile = sys.stdout
   print('%s,%s,%s,%s' % ('file','min_sup','min_conf',''), file=outfile)
   print('%s,%s,%s,%s' % (data_filename,min_sup,min_conf,''), file=outfile)
   with open('results_freq_%.3f_%.3f.csv' % (min_sup, min_conf), 'w') as file:
      apriori.print_items_csv(transactions, beers_db, frequent, file=file)
   with open('results_rule_%.3f_%.3f.csv' % (min_sup, min_conf), 'w') as file:
      apriori.print_rules_csv(transactions, beers_db, rules, file=file)
   apriori.print_items_csv(transactions, beers_db, frequent)
   apriori.print_rules_csv(transactions, beers_db, rules)
   return 0
Exemple #2
0
def main():
   # PARSE ARGS
   data_filename = None
   min_sup = None
   min_conf = None
   arg_parser = lab6.get_association_args()
   args = arg_parser.parse_args()
   data_filename = args.csv_filename
   min_sup = args.min_sup
   min_conf = args.min_conf
   # BUILD GOODS DB
   tags_db = TagsDatabase('alltags.csv')
   # BUILD BASKETS
   transactions = MarketBasketTransactions(data_filename)
   # CALC ASSOCIATIONS
   apriori = Apriori()
   frequent, rules = apriori.get_associations(transactions, min_sup, min_conf)
   outfile = sys.stdout
   print('%s,%s,%s,%s' % ('file','min_sup','min_conf',''), file=outfile)
   print("--------------")
   print('%s,%s,%s,%s' % (data_filename,min_sup,min_conf,''), file=outfile)
   print("--------------")
   apriori.print_items_csv(transactions, tags_db, frequent)
   print("--------------")
   apriori.print_rules_csv(transactions, tags_db, rules)
   return 0