Extracting weights and tree structures from xgboost - plot trees
You can dump the xgboost model into a text file, and parse it yourself. The file looks like this:
booster[0(<-tree id)]:
0(<-node id):[f317(<-feature name)<0.187154] yes=1(<-child node id),no=2,missing=1
    1:[f317<0.071172] yes=3,no=4,missing=3
         ...
            6379:leaf=0.125 (<-weight to that leaf)
At the end, it is the weighted sum of all leaves. This is in case of binary classification and regression.
I'm using xgboost package in python and I'm going to extract tree structures after training. For instance, I'm going to know the feature and threshold that has been selected at each node to export the tree structures to a function.
Moreover, I need to know the weight of each tree after training. (As we know, the result of trees will be combined like w1*h1+w2h2+...+wn*hn, in which wi is weigh and hi is the answer of ith tree in boosting). Actually, I need to have access to weights and inner trees. I'm doing classification.
My other question is that, when I use "from xgboost import plot_tree", I receive this error "the package does not have this function". How can I plot my trees?
Thanks