lgb.importance.Rd 1.35 KB
Newer Older
Guolin Ke's avatar
Guolin Ke committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lgb.importance.R
\name{lgb.importance}
\alias{lgb.importance}
\title{Compute feature importance in a model}
\usage{
lgb.importance(model, percentage = TRUE)
}
\arguments{
\item{model}{object of class \code{lgb.Booster}.}

\item{percentage}{whether to show importance in relative percentage.}
}
\value{
For a tree model, a \code{data.table} with the following columns:
\itemize{
17
18
19
20
  \item{\code{Feature}: Feature names in the model.}
  \item{\code{Gain}: The total gain of this feature's splits.}
  \item{\code{Cover}: The number of observation related to this feature.}
  \item{\code{Frequency}: The number of times a feature splited in trees.}
Guolin Ke's avatar
Guolin Ke committed
21
22
23
24
25
26
}
}
\description{
Creates a \code{data.table} of feature importances in a model.
}
\examples{
27
\donttest{
28
29
\dontshow{setLGBMthreads(2L)}
\dontshow{data.table::setDTthreads(1L)}
Guolin Ke's avatar
Guolin Ke committed
30
31
32
33
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)

34
35
params <- list(
  objective = "binary"
36
  , learning_rate = 0.1
37
38
39
  , max_depth = -1L
  , min_data_in_leaf = 1L
  , min_sum_hessian_in_leaf = 1.0
40
  , num_threads = 2L
41
)
42
43
44
45
46
model <- lgb.train(
    params = params
    , data = dtrain
    , nrounds = 5L
)
Guolin Ke's avatar
Guolin Ke committed
47
48
49

tree_imp1 <- lgb.importance(model, percentage = TRUE)
tree_imp2 <- lgb.importance(model, percentage = FALSE)
50
}
Guolin Ke's avatar
Guolin Ke committed
51
}