lgb.plot.importance.Rd 1.8 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.importance.R
\name{lgb.plot.importance}
\alias{lgb.plot.importance}
\title{Plot feature importance as a bar graph}
\usage{
7
8
lgb.plot.importance(
  tree_imp,
9
  top_n = 10L,
10
  measure = "Gain",
11
  left_margin = 10L,
12
13
  cex = NULL
)
Guolin Ke's avatar
Guolin Ke committed
14
15
16
17
18
19
20
21
22
23
}
\arguments{
\item{tree_imp}{a \code{data.table} returned by \code{\link{lgb.importance}}.}

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

\item{measure}{the name of importance measure to plot, can be "Gain", "Cover" or "Frequency".}

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

24
25
26
\item{cex}{(base R barplot) passed as \code{cex.names} parameter to \code{\link[graphics]{barplot}}.
Set a number smaller than 1.0 to make the bar labels smaller than R's default and values
greater than 1.0 to make them larger.}
Guolin Ke's avatar
Guolin Ke committed
27
28
29
30
31
32
33
34
35
36
37
38
}
\value{
The \code{lgb.plot.importance} function creates a \code{barplot}
and silently returns a processed data.table with \code{top_n} features sorted by defined importance.
}
\description{
Plot previously calculated feature importance: Gain, Cover and Frequency, as a bar graph.
}
\details{
The graph represents each feature as a horizontal bar of length proportional to the defined importance of a feature.
Features are shown ranked in a decreasing importance order.
}
39
40
41
42
43
44
45
46
\examples{
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)

params <- list(
    objective = "binary"
    , learning_rate = 0.01
47
48
49
50
    , num_leaves = 63L
    , max_depth = -1L
    , min_data_in_leaf = 1L
    , min_sum_hessian_in_leaf = 1.0
51
52
)

53
model <- lgb.train(params, dtrain, 10L)
54
55

tree_imp <- lgb.importance(model, percentage = TRUE)
56
lgb.plot.importance(tree_imp, top_n = 10L, measure = "Gain")
57
}