module grammar_sklearn.g_sklearn_tree

Short summary

module mlprodict.grammar_sklearn.g_sklearn_tree

List of converters from scikit-learn model.

source on GitHub

Functions

function

truncated documentation

sklearn_decision_tree_regressor

Converts a DecisionTreeRegressor

Documentation

List of converters from scikit-learn model.

source on GitHub

mlprodict.grammar_sklearn.g_sklearn_tree.sklearn_decision_tree_regressor(model, input_names=None, output_names=None, **kwargs)[source]

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

Parameters
  • model – scikit-learn model

  • input_names – name of the input features

  • output_names – name of the output predictions

  • no_loop – implements the model without any loop

Returns

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.

Note

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]
        else:
            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