Parse a boosted tree model text dump into a
1 2 3 4 5 6 7 8
character vector of feature names. If the model already
contains feature names, those would be used when
object of class
an integer vector of tree indices that should be parsed.
If set to
a logical flag indicating whether nodes in columns "Yes", "No", "Missing" should be represented as integers (when FALSE) or as "Tree-Node" character strings (when FALSE).
currently not used.
data.table with detailed information about model trees' nodes.
The columns of the
Tree: integer ID of a tree in a model (zero-based index)
Node: integer ID of a node in a tree (zero-based index)
ID: character identifier of a node in a model (only when
Feature: for a branch node, it's a feature id or name (when available);
for a leaf note, it simply labels it as
Split: location of the split for a branch node (split condition is always "less than")
Yes: ID of the next node when the split condition is met
No: ID of the next node when the split condition is not met
Missing: ID of the next node when branch value is missing
Quality: either the split gain (change in loss) or the leaf value
Cover: metric related to the number of observation either seen by a split
or collected by a leaf during training.
use_int_id=FALSE, columns "Yes", "No", and "Missing" point to model-wide node identifiers
in the "ID" column. When
use_int_id=TRUE, those columns point to node identifiers from
the corresponding trees in the "Node" column.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Basic use: data(agaricus.train, package='xgboost') bst <- xgboost(data = agaricus.train$data, label = agaricus.train$label, max_depth = 2, eta = 1, nthread = 2, nrounds = 2,objective = "binary:logistic") (dt <- xgb.model.dt.tree(colnames(agaricus.train$data), bst)) # This bst model already has feature_names stored with it, so those would be used when # feature_names is not set: (dt <- xgb.model.dt.tree(model = bst)) # How to match feature names of splits that are following a current 'Yes' branch: merge(dt, dt[, .(ID, Y.Feature=Feature)], by.x='Yes', by.y='ID', all.x=TRUE)[order(Tree,Node)]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.