Skip to content

_node

Node ⚓︎

Node object for building a decision tree.

Parameters:

Name Type Description Default
feature int index, optional

index of the best feature for splitting this Node, by default None

None
threshold float, optional

the threshold for the best split of the data, by default None

None
left Node, optional

the left child of this Node also of class Node, by default None

None
right Node, optional

the right child of this Node also of class Node, by default None

None
majority_class int, optional

The majority class in this node, only if this Node is a leaf, by default None

None
class_probs 1d ndarray, optional

An array of class probabilities for this node, only if this Node is a leaf, by default None

None
Source code in mlproject/decision_tree/_node.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Node:
    """Node object for building a decision tree.

    Parameters
    ----------
    feature : int index, optional
        index of the best feature for splitting this Node, by default None
    threshold : float, optional
        the threshold for the best split of the data, by default None
    left : Node, optional
        the left child of this Node also of class Node, by default None
    right : Node, optional
        the right child of this Node also of class Node, by default None
    majority_class : int, optional
        The majority class in this node, only if this Node is a leaf, by default None
    class_probs : 1d ndarray, optional
        An array of class probabilities for this node, only if this Node is a leaf, by default None
    """

    def __init__(
        self,
        left=None,
        right=None,
        feature=None,
        threshold=None,
        *,
        majority_class=None,
        class_probs=None
    ):
        self.feature = feature
        self.threshold = threshold
        self.left, self.right = left, right
        self.majority_class = majority_class
        self.class_probs = class_probs

    def is_leaf(self):
        """Returns True if this Node is a leaf node, otherwise False

        Returns
        -------
        bool
            True if this Node is a leaf node, otherwise False
        """

        return self.majority_class is not None

is_leaf() ⚓︎

Returns True if this Node is a leaf node, otherwise False

Returns:

Type Description
bool

True if this Node is a leaf node, otherwise False

Source code in mlproject/decision_tree/_node.py
39
40
41
42
43
44
45
46
47
48
def is_leaf(self):
    """Returns True if this Node is a leaf node, otherwise False

    Returns
    -------
    bool
        True if this Node is a leaf node, otherwise False
    """

    return self.majority_class is not None