Add a leaf node to the tree ensemble. Parameters ---------- tree_id: int ID of the tree to add the node to. node_id: int ID of the node within the tree. values: [float | int | list | dict] Value(s) at the leaf no
(self, tree_id, node_id, values, relative_hit_rate=None)
| 198 | spec_node.missingValueTracksTrueChild = missing_value_tracks_true_child |
| 199 | |
| 200 | def add_leaf_node(self, tree_id, node_id, values, relative_hit_rate=None): |
| 201 | """ |
| 202 | Add a leaf node to the tree ensemble. |
| 203 | |
| 204 | Parameters |
| 205 | ---------- |
| 206 | tree_id: int |
| 207 | ID of the tree to add the node to. |
| 208 | |
| 209 | node_id: int |
| 210 | ID of the node within the tree. |
| 211 | |
| 212 | values: [float | int | list | dict] |
| 213 | Value(s) at the leaf node to add to the prediction when this node is |
| 214 | activated. If the prediction dimension of the tree is 1, then the |
| 215 | value is specified as a float or integer value. |
| 216 | |
| 217 | For multidimensional predictions, the values can be a list of numbers |
| 218 | with length matching the dimension of the predictions or a dictionary |
| 219 | mapping index to value added to that dimension. |
| 220 | |
| 221 | Note that the dimension of any tree must match the dimension given |
| 222 | when :py:meth:`set_default_prediction_value` is called. |
| 223 | |
| 224 | """ |
| 225 | spec_node = self.tree_parameters.nodes.add() |
| 226 | spec_node.treeId = tree_id |
| 227 | spec_node.nodeId = node_id |
| 228 | spec_node.nodeBehavior = ( |
| 229 | _proto.TreeEnsemble_pb2.TreeEnsembleParameters.TreeNode.TreeNodeBehavior.Value( |
| 230 | "LeafNode" |
| 231 | ) |
| 232 | ) |
| 233 | |
| 234 | if not isinstance(values, _collections.abc.Iterable): |
| 235 | values = [values] |
| 236 | |
| 237 | if relative_hit_rate is not None: |
| 238 | spec_node.relativeHitRate = relative_hit_rate |
| 239 | |
| 240 | if type(values) == dict: |
| 241 | iter = values.items() |
| 242 | else: |
| 243 | iter = enumerate(values) |
| 244 | |
| 245 | for index, value in iter: |
| 246 | ev_info = spec_node.evaluationInfo.add() |
| 247 | ev_info.evaluationIndex = index |
| 248 | ev_info.evaluationValue = float(value) |
| 249 | spec_node.nodeBehavior = ( |
| 250 | _proto.TreeEnsemble_pb2.TreeEnsembleParameters.TreeNode.TreeNodeBehavior.Value( |
| 251 | "LeafNode" |
| 252 | ) |
| 253 | ) |
| 254 | |
| 255 | |
| 256 | class TreeEnsembleRegressor(TreeEnsembleBase): |
no test coverage detected