-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_mining.py
39 lines (34 loc) · 1.15 KB
/
test_mining.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from tempfile import TemporaryDirectory
from rule_mining import fit, Rule, match_rules
# from rule_utils import match_rules
def test_fit():
dataset = [
[0, 1, 2],
[0, 1, 2],
[0, 1, 3],
[0, 1, 3],
[0, 1, 4],
[0, 1, 4],
]
answers = [0, 0, 1, 1, 2, 2]
rules = fit(dataset, answers, support_gminer=0.2)
assert len(rules) == 4
for k, (itemset, ans) in enumerate([[(2,), 0], [(3,), 1], [(4,), 2], [(), 0],]):
assert rules[k].itemset == itemset
assert rules[k].ans == ans
# match_rules(dataset, rules)
all_rules, correct_rules = match_rules(dataset, rules, answers=answers, bsize=10)
print(all_rules)
# item 0
assert len(all_rules[0]) == 2
assert all_rules[0][0].itemset == (2,)
assert all_rules[0][1].itemset == ()
assert len(correct_rules[0]) == 2
assert correct_rules[0][0].itemset == (2,)
assert correct_rules[0][1].itemset == ()
# item 2
assert len(all_rules[2]) == 2
assert all_rules[2][0].itemset == (3,)
assert all_rules[2][1].itemset == ()
assert len(correct_rules[2]) == 1
assert correct_rules[2][0].itemset == (3,)