Exemplo n.º 1
0
 def test_internal_prune(self):
     updated_c = LeafNode(Split(self.data))
     prune_mutation = TreeMutation("prune", self.c, updated_c)
     mutate(self.tree, prune_mutation)
     self.assertIn(updated_c, self.tree.leaf_nodes)
     self.assertNotIn(self.c, self.tree.nodes)
     self.assertNotIn(self.d, self.tree.nodes)
     self.assertNotIn(self.e, self.tree.nodes)
Exemplo n.º 2
0
 def test_grow(self):
     f, g = LeafNode(Split(self.data)), LeafNode(Split(self.data))
     updated_d = DecisionNode(Split(self.data), f, g)
     grow_mutation = TreeMutation("grow", self.d, updated_d)
     mutate(self.tree, grow_mutation)
     self.assertIn(updated_d, self.tree.decision_nodes)
     self.assertIn(updated_d, self.tree.prunable_decision_nodes)
     self.assertIn(f, self.tree.leaf_nodes)
     self.assertNotIn(self.d, self.tree.nodes)
Exemplo n.º 3
0
    def setUp(self):
        self.data = Data(
            pd.DataFrame({
                "a": [1, 2, 3],
                "b": [1, 2, 3]
            }).values, np.array([1, 2, 3]))

        self.a = split_node(LeafNode(Split(
            self.data)), (SplitCondition(0, 1, le), SplitCondition(0, 1, gt)))
        self.b = self.a.left_child
        self.x = self.a.right_child
        self.tree = Tree([self.a, self.b, self.x])

        self.c = split_node(
            self.a._right_child,
            (SplitCondition(1, 2, le), SplitCondition(1, 2, gt)))
        mutate(self.tree, TreeMutation("grow", self.x, self.c))

        self.d = self.c.left_child
        self.e = self.c.right_child
Exemplo n.º 4
0
    def setUp(self):
        X = format_covariate_matrix(
            pd.DataFrame({
                "a": [1, 2, 3],
                "b": [1, 2, 3]
            }))
        self.data = Data(X, np.array([1, 2, 3]).astype(float))

        self.a = split_node(LeafNode(Split(
            self.data)), (SplitCondition(0, 1, le), SplitCondition(0, 1, gt)))
        self.b = self.a.left_child
        self.x = self.a.right_child
        self.tree = Tree([self.a, self.b, self.x])

        self.c = split_node(
            self.a._right_child,
            (SplitCondition(1, 2, le), SplitCondition(1, 2, gt)))
        mutate(self.tree, TreeMutation("grow", self.x, self.c))

        self.d = self.c.left_child
        self.e = self.c.right_child