Tree Utilities

Tree parsing utilities and lightweight tree data structures.

class Node(node_id, *, feature=None, value=None, parent=None, threshold=None, code=None, n_samples=0, left=None, right=None)[source]

Bases: NodeMixin

Node in a parsed decision tree.

property code
property feature
property left
property length
property n_samples
property node_id
property right
property sigma
property threshold
property value
class Tree(root)[source]

Bases: object

In-memory representation of a parsed tree ensemble member.

property adaboost
property leaves
property logit
property max_depth
property n_nodes
nodes_at(depth)[source]
property shape
property xgboost
root
parse_ensembles(*ensembles, mapper)[source]

Flatten and parse one or more supported tree ensembles.

Returns:

Parsed trees from every provided ensemble, flattened into one tuple.

Return type:

tuple[Tree, …]

parse_tree(tree, *, mapper, is_adaboost=False)[source]

Convert a fitted scikit-learn tree into an OCEAN tree.

Returns:

Parsed tree structure used by the optimization backends.

Return type:

Tree

parse_trees(trees, *, mapper, is_adaboost=False)[source]

Parse an iterable of fitted scikit-learn trees.

Returns:

Parsed tree structures in the same order as the input iterable.

Return type:

tuple[Tree, …]