module grammar.grammar_sklearn.g_sklearn_tree#

Short summary#

module mlprodict.grammar.grammar_sklearn.g_sklearn_tree

List of converters from scikit-learn model.

source on GitHub



truncated documentation


Converts a DecisionTreeRegressor


List of converters from scikit-learn model.

source on GitHub

mlprodict.grammar.grammar_sklearn.g_sklearn_tree.sklearn_decision_tree_regressor(model, input_names=None, output_names=None, **kwargs)#

Converts a DecisionTreeRegressor model into a grammar model (semantic graph representation).

  • model – scikit-learn model

  • input_names – name of the input features

  • output_names – name of the output predictions

  • kwargs – addition parameter (with_loop)


graph model

If input is None or output is None, default values will be given to the outputs ['Prediction', 'Score'] for the outputs. If input_names is None, it wil be 'Features'.

Additional parameters: - with_loop: False by default, True not implemented.


The code to compute on output is here:

for i in range(n_samples):
    node = self.nodes
    # While node not a leaf
    while node.left_child != _TREE_LEAF:
        # ... and node.right_child != _TREE_LEAF:
        if X_ptr[X_sample_stride * i +
                 X_fx_stride * node.feature] <= node.threshold:
            node = &self.nodes[node.left_child]
            node = &self.nodes[node.right_child]

    out_ptr[i] = <SIZE_t>(node - self.nodes)  # node offset

TODO: improve C code (all leaves are computed and this is unnecessary). TODO: create a function tree and an intermediate node and use it here.

source on GitHub