Description Usage Arguments Value Examples
View source: R/xgb.wrap.metric.R
The wrapper works only if both the wrapper and the original evaluation metric are existing. Requires Matrix
and xgboost
packages.
1 | xgb.wrap.metric(f, name)
|
f |
Type: function. The function to wrap from xgboost. Requires the following order of arguments for the function to work: |
name |
Type: character. The evaluation metric name which is printed and used for xgboost variables. |
The wrapping function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # Note: this example unexpectedly fails when using pkgdown.
library(xgboost)
library(Matrix)
data(agaricus.train, package = "xgboost")
data(agaricus.test, package = "xgboost")
dtrain <- xgboost::xgb.DMatrix(agaricus.train$data, label = agaricus.train$label)
dtest <- xgboost::xgb.DMatrix(agaricus.test$data, label = agaricus.test$label)
watchlist <- list(train = dtrain, eval = dtest)
evalerror <- function(preds, labels) {
return(mean(abs(preds - labels)))
}
evalerror_wrap <- xgb.wrap.metric(f = evalerror, "mae")
param <- list(max_depth = 2, eta = 1, silent = 1, nthread = 1,
objective = "binary:logistic", eval_metric = evalerror_wrap)
bst <- xgboost::xgb.train(param, dtrain, nrounds = 2, watchlist)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.