def test_build_tree_rec_leaf(self): fLabel = randbool() listInst = [dtree.Instance([], fLabel)] * random.randint(1, 3) dt = dtree.build_tree_rec([], listInst, 0.0, -1) self.assert_dt_members(dt) self.assertTrue(dt.is_leaf(), "dt was not a leaf") self.assertEqual(dt.fLabel, fLabel)
def test_build_tree_rec_leaf(self): fLabel = randbool() listInst = [dtree.Instance([],fLabel)]*random.randint(1,3) dt = dtree.build_tree_rec([],listInst,0.0,-1) self.assert_dt_members(dt) self.assertTrue(dt.is_leaf(), "dt was not a leaf") self.assertEqual(dt.fLabel, fLabel)
def test_build_tree_rec_stump(self): pairBounds = (5,10) build_list_inst_bool = (lambda f: [dtree.Instance([int(f),randbool()],fLabel=f) for _ in xrange(random.randint(*pairBounds))]) listInst = build_list_inst_bool(True) + build_list_inst_bool(False) setIxAttr = set(range(2)) dt = dtree.build_tree_rec(setIxAttr, listInst, 0.0,-1) self.assertTrue(dt.is_node(), "dt was not a node") self.assertEqual(dt.ixAttr, 0) dt0 = dt.dictChildren[0] dt1 = dt.dictChildren[1] for dtChild,fExpected in ((dt0,False), (dt1,True)): self.assertTrue(dtChild.is_leaf(), "dtChild was not a leaf") self.assertEqual(dtChild.fLabel, fExpected)
def test_build_tree_rec_stump(self): pairBounds = (5, 10) build_list_inst_bool = (lambda f: [ dtree.Instance([int(f), randbool()], fLabel=f) for _ in xrange(random.randint(*pairBounds)) ]) listInst = build_list_inst_bool(True) + build_list_inst_bool(False) setIxAttr = set(range(2)) dt = dtree.build_tree_rec(setIxAttr, listInst, 0.0, -1) self.assertTrue(dt.is_node(), "dt was not a node") self.assertEqual(dt.ixAttr, 0) dt0 = dt.dictChildren[0] dt1 = dt.dictChildren[1] for dtChild, fExpected in ((dt0, False), (dt1, True)): self.assertTrue(dtChild.is_leaf(), "dtChild was not a leaf") self.assertEqual(dtChild.fLabel, fExpected)