Traverse through the tree and append to the tree spec.

def _recurse(coreml_tree, scikit_tree, tree_id, node_id, scaling = 1.0, mode = 'regressor',
             n_classes = 2, tree_index = 0):
    """Traverse through the tree and append to the tree spec.
    """
    if not(HAS_SKLEARN):
        raise RuntimeError('scikit-learn not found. scikit-learn conversion API is disabled.')

    ## Recursion should not be called on the leaf node.
    if node_id == _tree.TREE_LEAF:
        raise ValueError("Invalid node_id %s" % _tree.TREE_LEAF)

    # Add a branch node to the tree
    if scikit_tree.children_left[node_id] != _tree.TREE_LEAF:
        branch_mode = 'BranchOnValueLessThanEqual'
        feature_index = scikit_tree.feature[node_id]
        feature_value = scikit_tree.threshold[node_id]
        left_child_id = scikit_tree.children_left[node_id]
        right_child_id = scikit_tree.children_right[node_id]

        # Add a branch node
        coreml_tree.add_branch_node(tree_id, node_id, feature_index,
                feature_value, branch_mode, left_child_id, right_child_id)

        # Now recurse
        _recurse(coreml_tree, scikit_tree, tree_id, left_child_id, scaling, mode, n_classes, tree_index)
        _recurse(coreml_tree, scikit_tree, tree_id, right_child_id, scaling, mode, n_classes, tree_index)

    # Add a leaf node to the tree
    else:
        # Get the scikit-learn value
        if scikit_tree.n_outputs != 1:
            raise ValueError('Expected only 1 output in the scikit-learn tree.')
        value = _get_value(scikit_tree.value[node_id], mode, scaling, n_classes, tree_index)
        coreml_tree.add_leaf_node(tree_id, node_id, value)