def speeds(): """ Test the naive rule finder vs. the simple one from the paper. """ import random random.seed(123456) transactions = generate_transactions(num_transactions=random.randint( 250, 500), unique_items=random.randint(8, 9), items_row=(10, 50)) itemsets, num_transactions = itemsets_from_transactions(transactions, 0.1) import time min_conf = 0.5 print(itemsets) st = time.perf_counter() rules_apri = generate_rules_apriori(itemsets, min_conf, num_transactions) rules_apri = list(rules_apri) time_formatted = round(time.perf_counter() - st, 40) print('Fast apriori ran in {} s'.format(time_formatted)) st = time.perf_counter() rules_simple = generate_rules_simple(itemsets, min_conf, num_transactions) rules_simple = list(rules_simple) time_formatted = round(time.perf_counter() - st, 40) print('Simple apriori ran in {} s'.format(time_formatted)) st = time.perf_counter() rules_naive = generate_rules_naively(itemsets, min_conf, num_transactions) rules_naive = list(rules_naive) time_formatted = round(time.perf_counter() - st, 40) print('Naive apriori ran in {} s'.format(time_formatted))
def test_generate_rules_simple_vs_naive(transactions): """ Test the naive rule finder vs. the simple one from the paper. """ itemsets, num_transactions = itemsets_from_transactions(transactions, 0.25) min_conf = 0.1 rules_naive = generate_rules_naively(itemsets, min_conf, num_transactions) rules_simple = generate_rules_simple(itemsets, min_conf, num_transactions) assert set(rules_naive) == set(rules_simple)