Пример #1
0
 def predict(self, X):
     """
     Predict the values for the input in X
     """
     # split data set
     assert self.tree, "The tree must exist, call fit before predict!"
     y = np.zeros((X.shape[0], ))
     # propagate the values down the leaves
     for leaf in self.tree.leaves:
         indices = np.array([True] * X.shape[0])  # initialize dummy index
         for ancestor in NodeMixin.iter_path_reverse(
                 leaf):  # iteration begins at the leaf node
             if ancestor.is_leaf:
                 left = ancestor.left
             else:
                 left_indices = X[:, ancestor.
                                  split_feature] <= ancestor.split_value
                 if left:
                     indices &= left_indices
                 else:
                     indices &= ~left_indices
                 left = ancestor.left
         y[indices] = leaf.value
     return y
Пример #2
0
 def __init__(self, treeDeep, continuous):
     self.__tree = NodeMixin()
     self.__treeDeep = treeDeep
     self.__continuous = continuous
Пример #3
0
def test_parent():
    """Parent attribute."""
    foo = NodeMixin()
    assert foo.parent is None
Пример #4
0
 def __init__(self, treeDeep, continuous):
     super().__init__(treeDeep, continuous)
     # http://anytree.readthedocs.io/en/latest/
     self.__tree = NodeMixin()