lgb.wrap.metric: LightGBM evaluation metric wrapper

Description Usage Arguments Value Examples

View source: R/lgb.wrap.metric.R

Description

The wrapper works only if both the wrapper and the original evaluation metric are existing. Requires Matrix and lightgbm packages.

Usage

1
lgb.wrap.metric(f, name, higher_better = FALSE)

Arguments

f

Type: function. The function to wrap from LightGBM. Requires the following order of arguments for the function to work: preds, labels, and returns a single value.

name

Type: character. The evaluation metric name which is printed and used for LightGBM variables.

higher_better

Type: logical. Whether a higher value means it is better. Defaults to FALSE.

Value

The wrapping function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# Note: this example unexpectedly fails when using pkgdown.

library(lightgbm)
library(Matrix)
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)

evalerror <- function(preds, labels) {
  return(mean(abs(preds - labels)))
}
evalerror_wrap <- lgb.wrap.metric(f = evalerror, "mae", FALSE)
params <- list(learning_rate = 1, min_data = 1, nthread = 1)

set.seed(1)
model <- lgb.cv(params,
                dtrain,
                2,
                nfold = 5,
                objective = "regression",
                eval = evalerror_wrap)

Laurae2/LauraeDS documentation built on May 29, 2019, 2:25 p.m.