lgb.plot.interpretation.Rd 1.88 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.plot.interpretation.R
\name{lgb.plot.interpretation}
\alias{lgb.plot.interpretation}
\title{Plot feature contribution as a bar graph}
\usage{
7
8
lgb.plot.interpretation(
  tree_interpretation_dt,
9
10
11
  top_n = 10L,
  cols = 1L,
  left_margin = 10L,
12
13
  cex = NULL
)
Guolin Ke's avatar
Guolin Ke committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
}
\arguments{
\item{tree_interpretation_dt}{a \code{data.table} returned by \code{\link{lgb.interprete}}.}

\item{top_n}{maximal number of top features to include into the plot.}

\item{cols}{the column numbers of layout, will be used only for multiclass classification feature contribution.}

\item{left_margin}{(base R barplot) allows to adjust the left margin size to fit feature names.}

\item{cex}{(base R barplot) passed as \code{cex.names} parameter to \code{barplot}.}
}
\value{
The \code{lgb.plot.interpretation} function creates a \code{barplot}.
}
\description{
Plot previously calculated feature contribution as a bar graph.
}
\details{
33
34
The graph represents each feature as a horizontal bar of length proportional to the defined
contribution of a feature. Features are shown ranked in a decreasing contribution order.
Guolin Ke's avatar
Guolin Ke committed
35
36
}
\examples{
37
38
39
40
\donttest{
Logit <- function(x) {
  log(x / (1.0 - x))
}
Guolin Ke's avatar
Guolin Ke committed
41
data(agaricus.train, package = "lightgbm")
42
43
44
45
46
47
48
labels <- agaricus.train$label
dtrain <- lgb.Dataset(
  agaricus.train$data
  , label = labels
)
setinfo(dtrain, "init_score", rep(Logit(mean(labels)), length(labels)))

Guolin Ke's avatar
Guolin Ke committed
49
50
data(agaricus.test, package = "lightgbm")

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

64
65
66
67
68
69
70
tree_interpretation <- lgb.interprete(
  model = model
  , data = agaricus.test$data
  , idxset = 1L:5L
)
lgb.plot.interpretation(
  tree_interpretation_dt = tree_interpretation[[1L]]
71
  , top_n = 3L
72
73
)
}
Guolin Ke's avatar
Guolin Ke committed
74
}