def test_compare(self): row1 = [1, 1, 0] header1 = ["A", "B", "C"] transaction1 = Transaction(row1, header1, ("Class", 0)) item1 = Item("A", 1) item2 = Item("B", 1) item3 = Item("C", 0) item4 = Item("B", 5) ant1 = Antecedent([item1, item2]) ant2 = Antecedent([item2]) ant3 = Antecedent([item3]) ant4 = Antecedent([item4]) assert ant1 <= transaction1 assert ant2 <= transaction1 assert ant3 <= transaction1 self.assertFalse(ant4 <= transaction1) assert transaction1 >= ant1 assert transaction1 >= ant2 assert transaction1 >= ant3
def test_hash(self): item1 = Item("a", 3) item2 = Item("b", 3) item3 = Item("c", 2) ant1 = Antecedent([item1, item2, item3]) ant2 = Antecedent([item1, item2, item3]) assert hash(ant1) == hash(ant2) assert ant1 == ant2
def test_len(self): item1 = Item("a", 3) item2 = Item("b", 3) item3 = Item("c", 2) item4 = Item("c", 4) ant1 = Antecedent([item1, item2, item3]) ant2 = Antecedent([item1, item2, item3, item4]) assert len(ant1) == 3 assert len(ant2) == 3
def test_init(self): item1 = Item("a", 3) item2 = Item("a", 3) item3 = Item("c", 2) ant1 = Antecedent([item1, item2, item3]) assert len(ant1.itemset) == 2
def test_getattr(self): item1 = Item("a", 3) item2 = Item("b", 3) item3 = Item("c", 2) ant1 = Antecedent([item1, item2, item3]) assert ant1.a == "3" assert ant1.b == "3" assert ant1.c == "2"
def test_getitem(self): item1 = Item("a", 3) item2 = Item("b", 3) item3 = Item("c", 2) ant1 = Antecedent([item1, item2, item3]) assert ant1[0] in [item1, item2, item3] assert ant1[1] in [item1, item2, item3] assert ant1[2] in [item1, item2, item3]
def test_len(self): item1 = Item("A", 1) item2 = Item("B", 1) ant1 = Antecedent([item1, item2]) cons1 = Consequent("Y", 1) car1 = ClassAssocationRule(ant1, cons1, 0.5, 0.9) assert len(car1) == 3
def test_compare(self): row1 = [1, 1, 0] header1 = ["A", "B", "C"] transaction1 = Transaction(row1, header1, ("Class", 0)) item1 = Item("A", 1) item2 = Item("B", 1) item3 = Item("C", 0) item4 = Item("B", 5) ant1 = Antecedent([item1, item2]) ant2 = Antecedent([item2]) ant3 = Antecedent([item3]) ant4 = Antecedent([item4]) cons1 = Consequent("Y", 1) cons2 = Consequent("Y", 2) cons3 = Consequent("Y", 3) # len: 2 car1 = ClassAssocationRule(ant1, cons1, 0.5, 0.9) # len: 1 car2 = ClassAssocationRule(ant2, cons2, 0.5, 0.9) car3 = ClassAssocationRule(ant3, cons3, 0.5, 0.9) car4 = ClassAssocationRule(ant4, cons3, 0.5, 1) sorted_cars = sorted([car1, car2, car3, car4], reverse=True) assert car1 < car2 assert car2 > car3 assert car3 < car2 assert car4 > car3 assert car1.antecedent <= transaction1 assert car2.antecedent <= transaction1 assert car3.antecedent <= transaction1 assert not car4.antecedent <= transaction1 assert sorted_cars[0] == car4
def test_createCARs(self): generated_rules = [('Y:=:1', (), 0.5, 0.5), ('Y:=:0', (), 0.5, 0.5), ('Y:=:1', ('A:=:1', ), 0.5, 1 / 3)] cars = createCARs(generated_rules) assert cars[0].consequent == Consequent("Y", 1) assert cars[0].confidence == 0.5 assert cars[0].support == 0.5 assert cars[1].consequent == Consequent("Y", 0) assert cars[1].confidence == 0.5 assert cars[1].support == 0.5 assert cars[2].consequent == Consequent("Y", 1) assert cars[2].antecedent == Antecedent([Item("A", 1)]) assert cars[2].confidence == 1 / 3 assert cars[2].support == 0.5