* [R] xgb.save must work when handle in nil but raw exists * [R] print.xgb.Booster should still print other info when handle is nil * [R] rename internal function xgb.Booster to xgb.Booster.handle to make its intent clear * [R] rename xgb.Booster.check to xgb.Booster.complete and make it visible; more docs * [R] storing evaluation_log should depend only on watchlist, not on verbose * [R] reduce the excessive chattiness of unit tests * [R] only disable some tests in windows when it's not 64-bit * [R] clean-up xgb.DMatrix * [R] test xgb.DMatrix loading from libsvm text file * [R] store feature_names in xgb.Booster, use them from utility functions * [R] remove non-functional co-occurence computation from xgb.importance * [R] verbose=0 is enough without a callback * [R] added forgotten xgb.Booster.complete.Rd; cran check fixes * [R] update installation instructions
71 lines
2.9 KiB
R
71 lines
2.9 KiB
R
% Generated by roxygen2: do not edit by hand
|
|
% Please edit documentation in R/xgb.model.dt.tree.R
|
|
\name{xgb.model.dt.tree}
|
|
\alias{xgb.model.dt.tree}
|
|
\title{Parse a boosted tree model text dump}
|
|
\usage{
|
|
xgb.model.dt.tree(feature_names = NULL, model = NULL, text = NULL,
|
|
trees = NULL, ...)
|
|
}
|
|
\arguments{
|
|
\item{feature_names}{character vector of feature names. If the model already
|
|
contains feature names, those would be used when \code{feature_names=NULL} (default value).
|
|
Non-null \code{feature_names} could be provided to override those in the model.}
|
|
|
|
\item{model}{object of class \code{xgb.Booster}}
|
|
|
|
\item{text}{\code{character} vector previously generated by the \code{xgb.dump}
|
|
function (where parameter \code{with_stats = TRUE} should have been set).
|
|
\code{text} takes precedence over \code{model}.}
|
|
|
|
\item{trees}{an integer vector of tree indices that should be parsed.
|
|
If set to \code{NULL}, all trees of the model are parsed.
|
|
It could be useful, e.g., in multiclass classification to get only
|
|
the trees of one certain class. IMPORTANT: the tree index in xgboost models
|
|
is zero-based (e.g., use \code{trees = 0:4} for first 5 trees).}
|
|
|
|
\item{...}{currently not used.}
|
|
}
|
|
\value{
|
|
A \code{data.table} with detailed information about model trees' nodes.
|
|
|
|
The columns of the \code{data.table} are:
|
|
|
|
\itemize{
|
|
\item \code{Tree}: ID of a tree in a model (integer)
|
|
\item \code{Node}: integer ID of a node in a tree (integer)
|
|
\item \code{ID}: identifier of a node in a model (character)
|
|
\item \code{Feature}: for a branch node, it's a feature id or name (when available);
|
|
for a leaf note, it simply labels it as \code{'Leaf'}
|
|
\item \code{Split}: location of the split for a branch node (split condition is always "less than")
|
|
\item \code{Yes}: ID of the next node when the split condition is met
|
|
\item \code{No}: ID of the next node when the split condition is not met
|
|
\item \code{Missing}: ID of the next node when branch value is missing
|
|
\item \code{Quality}: either the split gain (change in loss) or the leaf value
|
|
\item \code{Cover}: metric related to the number of observation either seen by a split
|
|
or collected by a leaf during training.
|
|
}
|
|
}
|
|
\description{
|
|
Parse a boosted tree model text dump into a \code{data.table} structure.
|
|
}
|
|
\examples{
|
|
# 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 has feature_names stored in it, so those would be used when
|
|
# the feature_names parameter is not provided:
|
|
(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)]
|
|
|
|
}
|
|
|