lgb.model.dt.tree.Rd 2.31 KB
Newer Older
Guolin Ke's avatar
Guolin Ke committed
1
2
3
4
5
6
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lgb.model.dt.tree.R
\name{lgb.model.dt.tree}
\alias{lgb.model.dt.tree}
\title{Parse a LightGBM model json dump}
\usage{
7
lgb.model.dt.tree(model, num_iteration = NULL, start_iteration = 1L)
Guolin Ke's avatar
Guolin Ke committed
8
9
}
\arguments{
10
\item{model}{object of class \code{lgb.Booster}.}
James Lamb's avatar
James Lamb committed
11

12
13
14
15
16
\item{num_iteration}{Number of iterations to include. NULL or <= 0 means use best iteration.}

\item{start_iteration}{Index (1-based) of the first boosting round to include in the output.
For example, passing \code{start_iteration=5, num_iteration=3} for a regression model
means "return information about the fifth, sixth, and seventh trees".}
Guolin Ke's avatar
Guolin Ke committed
17
18
19
20
21
22
23
}
\value{
A \code{data.table} with detailed information about model trees' nodes and leafs.

The columns of the \code{data.table} are:

\itemize{
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 \item{\code{tree_index}: ID of a tree in a model (integer)}
 \item{\code{split_index}: ID of a node in a tree (integer)}
 \item{\code{split_feature}: for a node, it's a feature name (character);
                             for a leaf, it simply labels it as \code{"NA"}}
 \item{\code{node_parent}: ID of the parent node for current node (integer)}
 \item{\code{leaf_index}: ID of a leaf in a tree (integer)}
 \item{\code{leaf_parent}: ID of the parent node for current leaf (integer)}
 \item{\code{split_gain}: Split gain of a node}
 \item{\code{threshold}: Splitting threshold value of a node}
 \item{\code{decision_type}: Decision type of a node}
 \item{\code{default_left}: Determine how to handle NA value, TRUE -> Left, FALSE -> Right}
 \item{\code{internal_value}: Node value}
 \item{\code{internal_count}: The number of observation collected by a node}
 \item{\code{leaf_value}: Leaf value}
 \item{\code{leaf_count}: The number of observation collected by a leaf}
Guolin Ke's avatar
Guolin Ke committed
39
40
41
42
43
44
}
}
\description{
Parse a LightGBM model json dump into a \code{data.table} structure.
}
\examples{
45
\donttest{
46
47
\dontshow{setLGBMthreads(2L)}
\dontshow{data.table::setDTthreads(1L)}
Guolin Ke's avatar
Guolin Ke committed
48
49
50
51
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)

52
53
54
params <- list(
  objective = "binary"
  , learning_rate = 0.01
55
56
57
58
  , num_leaves = 63L
  , max_depth = -1L
  , min_data_in_leaf = 1L
  , min_sum_hessian_in_leaf = 1.0
59
  , num_threads = 2L
60
)
61
model <- lgb.train(params, dtrain, 10L)
Guolin Ke's avatar
Guolin Ke committed
62
63

tree_dt <- lgb.model.dt.tree(model)
64
}
Guolin Ke's avatar
Guolin Ke committed
65
}