def test_parse_dataset(self): itemsets = parse.parse_dataset() assert itemsets and type(itemsets) is list itemset = itemsets[0] assert itemset and type(itemset) is frozenset item = random.choice(tuple(itemset)) assert item and type(item) is tuple
def test_apriori_gen(self): dataset = parse.parse_dataset() frequent_itemsets = generate.frequent_itemsets(0.05, dataset) l = frequent_itemsets[0] k = 2 C = generate.apriori_gen(l, k) assert type(C) is dict assert not C or random.choice(list(C.values())) is 0
def test_association_rules(self): dataset = parse.parse_dataset() frequent_itemsets = generate.frequent_itemsets(0.05, dataset) association_rules = generate.association_rules(dataset, frequent_itemsets, utils.Metric.Confidence, 0.3) assert association_rules and type(association_rules) is list rule = association_rules[0] assert type(rule[0]) is tuple assert type(rule[1]) is float assert type(rule[2]) is float
def test_frequent_itemsets(self): dataset = parse.parse_dataset() frequent_itemsets = generate.frequent_itemsets(0.05, dataset) assert frequent_itemsets assert len(frequent_itemsets) is len(dataset[0]) assert type(frequent_itemsets) is list one_itemsets = frequent_itemsets[0] assert type(one_itemsets) is set assert len(one_itemsets) is 0 or type(random.sample(one_itemsets, 1)[0]) is frozenset
def main(): support_threshold, metric, metric_threshold, filepath = interact.get_input() dataset = parse.parse_dataset(filepath) frequent_itemsets = generate.frequent_itemsets(support_threshold, dataset) interact.print_frequent_itemsets(frequent_itemsets, LOG_FILE) association_rules = generate.association_rules(dataset, frequent_itemsets, metric, metric_threshold) interact.print_association_rules(association_rules, LOG_FILE, metric) print("Log file written at {}".format(os.path.join(os.getcwd(), LOG_FILE)))