SplitNode¶
SplitNode
¶
Bases: InternalNode
Split node with a left and right child.
The plain SplitNode only splits the data and applies no model, so both side models are NoneNodeModel. Subclasses change the expected model type (model_type) and/or make the split categorical (categorical).
Attributes:
| Name | Type | Description |
|---|---|---|
pivot_value |
Union[float, list]
|
Threshold for a numeric split (left if x <= pivot_value), or the list of categories routed to the left child for a categorical split. |
left_child |
BaseNode
|
Child node for samples on the left of the split. |
right_child |
BaseNode
|
Child node for samples on the right of the split. |
left_model |
NodeModel
|
Model applied to samples on the left of the split. |
right_model |
NodeModel
|
Model applied to samples on the right of the split. |
Source code in imote/nodes/split_node.py
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
model_type = NoneNodeModel
class-attribute
instance-attribute
¶
Model class both side models must be an instance of.
categorical = False
class-attribute
instance-attribute
¶
Whether pivot_value is a list of left categories instead of a threshold.
__init__(indices: np.ndarray, y_res: np.ndarray, rss: float, pivot_idx: int, pivot_value: Union[float, list], left_child: BaseNode, right_child: BaseNode, left_model: NodeModel, right_model: NodeModel)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices
|
ndarray
|
Row indices of the samples belonging to this node. |
required |
y_res
|
ndarray
|
Residuals of the target variable at this node. |
required |
rss
|
float
|
Residual sum of squares at this node. |
required |
pivot_idx
|
int
|
Index of the feature the split is based on. |
required |
pivot_value
|
Union[float, list]
|
Threshold value, or list of left categories for a categorical split. |
required |
left_child
|
BaseNode
|
Child node for samples on the left of the split. |
required |
right_child
|
BaseNode
|
Child node for samples on the right of the split. |
required |
left_model
|
NodeModel
|
Model applied to samples on the left of the split. |
required |
right_model
|
NodeModel
|
Model applied to samples on the right of the split. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If a side model is not an instance of model_type, or pivot_value doesn't match the kind of split. |
Source code in imote/nodes/split_node.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
goes_left(value) -> bool
¶
Returns whether a sample with this pivot feature value goes to the left child.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Value of the sample at feature pivot_idx. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the sample is routed to the left child. |
Source code in imote/nodes/split_node.py
83 84 85 86 87 88 89 90 91 92 | |
goes_left_mask(values) -> np.ndarray
¶
Vectorized goes_left: returns a boolean mask of the values routed to the left child.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array of sample values at feature pivot_idx. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Boolean array, True where the sample goes to the left child. |
Source code in imote/nodes/split_node.py
94 95 96 97 98 99 100 101 102 103 104 105 | |
get_children() -> List[BaseNode]
¶
Returns this node's left and right children.
Returns:
| Type | Description |
|---|---|
List[BaseNode]
|
List of [left_child, right_child]. |
Source code in imote/nodes/split_node.py
107 108 109 110 111 112 113 | |
set_children(children: List[BaseNode])
¶
Replaces this node's left and right children.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
children
|
List[BaseNode]
|
List of [new_left_child, new_right_child]. |
required |
Source code in imote/nodes/split_node.py
115 116 117 118 119 120 121 122 | |
get_label() -> str
¶
Returns the full display label for this node.
Returns:
| Type | Description |
|---|---|
str
|
Label of the form " |
str
|
" |
Source code in imote/nodes/split_node.py
124 125 126 127 128 129 130 131 132 133 134 | |
to_dict() -> dict
¶
Serializes the node to a dictionary.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with base attributes plus pivot_idx, pivot_value, |
dict
|
both children's class names and serialized forms, and both |
dict
|
models' serialized forms. |
Source code in imote/nodes/split_node.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
from_dict(dic: dict) -> SplitNode
classmethod
¶
Reconstructs a SplitNode instance, including children and models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dic
|
dict
|
Dictionary previously produced by to_dict(). |
required |
Returns:
| Type | Description |
|---|---|
SplitNode
|
A new instance of cls with children and side models restored. |
Source code in imote/nodes/split_node.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
SplitCNode
¶
Bases: SplitNode
Categorical SplitNode: pivot_value lists the categories routed to the left child.
Source code in imote/nodes/split_node.py
180 181 182 183 184 | |
PlinNode
¶
Bases: SplitNode
PLIN: piecewise linear split with a SimpleLinearNodeModel on each side.
Source code in imote/nodes/split_node.py
187 188 189 190 191 | |
BlinNode
¶
Bases: SplitNode
BLIN: broken linear split, like PLIN but the two models are continuous at pivot_value.
Source code in imote/nodes/split_node.py
194 195 196 197 198 199 200 201 202 203 204 205 | |
PconNode
¶
Bases: SplitNode
PCON: piecewise constant split with a ConstantNodeModel on each side.
Source code in imote/nodes/split_node.py
208 209 210 211 212 | |
PconcNode
¶
Bases: PconNode
PCONC: categorical PCON, pivot_value lists the categories routed to the left child.
Source code in imote/nodes/split_node.py
215 216 217 218 219 | |