lgb.interprete.Rd 1.75 KB
Newer Older
Guolin Ke's avatar
Guolin Ke committed
1
2
3
4
5
6
7
8
9
10
11
12
13
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lgb.interprete.R
\name{lgb.interprete}
\alias{lgb.interprete}
\title{Compute feature contribution of prediction}
\usage{
lgb.interprete(model, data, idxset, num_iteration = NULL)
}
\arguments{
\item{model}{object of class \code{lgb.Booster}.}

\item{data}{a matrix object or a dgCMatrix object.}

14
\item{idxset}{an integer vector of indices of rows needed.}
Guolin Ke's avatar
Guolin Ke committed
15
16
17
18

\item{num_iteration}{number of iteration want to predict with, NULL or <= 0 means use best iteration.}
}
\value{
19
20
21
For regression, binary classification and lambdarank model, a \code{list} of \code{data.table}
        with the following columns:
        \itemize{
22
23
            \item{\code{Feature}: Feature names in the model.}
            \item{\code{Contribution}: The total contribution of this feature's splits.}
24
25
26
        }
        For multiclass classification, a \code{list} of \code{data.table} with the Feature column and
        Contribution columns to each class.
Guolin Ke's avatar
Guolin Ke committed
27
28
29
30
31
}
\description{
Computes feature contribution components of rawscore prediction.
}
\examples{
32
\donttest{
33
Logit <- function(x) log(x / (1.0 - x))
Guolin Ke's avatar
Guolin Ke committed
34
35
36
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)
37
38
39
40
41
set_field(
  dataset = dtrain
  , field_name = "init_score"
  , data = rep(Logit(mean(train$label)), length(train$label))
)
Guolin Ke's avatar
Guolin Ke committed
42
43
44
data(agaricus.test, package = "lightgbm")
test <- agaricus.test

45
46
params <- list(
    objective = "binary"
47
    , learning_rate = 0.1
48
49
50
    , max_depth = -1L
    , min_data_in_leaf = 1L
    , min_sum_hessian_in_leaf = 1.0
51
    , num_threads = 2L
52
)
53
54
55
56
57
model <- lgb.train(
    params = params
    , data = dtrain
    , nrounds = 3L
)
Guolin Ke's avatar
Guolin Ke committed
58

59
tree_interpretation <- lgb.interprete(model, test$data, 1L:5L)
60
}
Guolin Ke's avatar
Guolin Ke committed
61
}