def model_to_trees()

in src/ppxgboost/BoosterParser.py [0:0]


def model_to_trees(model, min_max):
    """
    Parse the model to trees
    :param min_max: dictionary key {'min','max'}
            min_max['min'] min_max['max']
    :param model: the xgboost model
    :return: the parse tree, the features in the xgboost model
    """
    # getting the dump of the tree.
    # list of string (representing trees)
    # the get_dump() returns a list strings, each tree is represented in a particular format
    # (seperated by \n or \t's.
    #  For example: one of the tree' string representation is below:
    #  '0:[XXX<3] yes=1,no=2,missing=1\n\t1:[Fare<13.6458502] yes=3,no=4,missing=3\n\t\t
    #  3:leaf=-0.00585523667\n\t\t4:leaf=0.0201724116\n\t2:leaf=-0.0114313215\n
    # -->
    # represents the following tree structure.
    # 0:[XXX<3] yes=1,no=2,missing=1
    #   1:[xyz<13.6458502] yes=3,no=4,missing=3
    # 	    3:leaf=-0.00585523667
    # 	    4:leaf=0.0201724116
    #   2:leaf=-0.0114313215
    trees_dump = model.get_dump()
    feature_set = set()
    # create an empty list
    output_trees = []
    # for each tree append the parsed string.

    for i in range(len(trees_dump)):
        # this parse the tree to the data structure.
        tree_object = parse_tree(trees_dump[i], feature_set, min_max)
        output_trees.append(tree_object)

    # output a list of the tree objects.
    return output_trees, feature_set, min_max