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)
示例#2
0
 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)
示例#3
0
文件: testdtree.py 项目: dzhu/cs181
 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)
示例#4
0
 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)