What is difference between eval_metric and feval in xgboost?
Asked Answered
K

2

13

What is difference between feval and eval_metric in xgb.train, both parametrs are only for evaluation purpose.

Post from Kaggle gives some insight :

https://www.kaggle.com/c/prudential-life-insurance-assessment/forums/t/18473/custom-objective-for-xgboost

Kuhn answered 20/10, 2016 at 16:8 Comment(0)
L
9

feval is to create your own customized evaluation metric.

  • it must be a (custom, user-defined) function

eval_metric is for built in metrics xgboost package is implementing.

  • it's a string, e.g. rmse / logloss/ mlogloss/ merror/ error/ auc/ ndcg/ ...
Lazos answered 7/12, 2017 at 8:18 Comment(0)
D
9

They both do roughly the same thing.

Eval_metric can take a string (uses their internal functions) or user defined function

feval only takes a function

Both are, as you noted, for evaluation purposes.

In the below examples you can see they are used very similarly.

## A simple xgb.train example:
param <- list(max_depth = 2, eta = 1, silent = 1, nthread = 2, 
              objective = "binary:logistic", eval_metric = "auc")
bst <- xgb.train(param, dtrain, nrounds = 2, watchlist)


## An xgb.train example where custom objective and evaluation metric are used:
logregobj <- function(preds, dtrain) {
   labels <- getinfo(dtrain, "label")
   preds <- 1/(1 + exp(-preds))
   grad <- preds - labels
   hess <- preds * (1 - preds)
   return(list(grad = grad, hess = hess))
}
evalerror <- function(preds, dtrain) {
  labels <- getinfo(dtrain, "label")
  err <- as.numeric(sum(labels != (preds > 0)))/length(labels)
  return(list(metric = "error", value = err))
}

# These functions could be used by passing them either:
#  as 'objective' and 'eval_metric' parameters in the params list:
param <- list(max_depth = 2, eta = 1, silent = 1, nthread = 2, 
              objective = logregobj, eval_metric = evalerror)
bst <- xgb.train(param, dtrain, nrounds = 2, watchlist)

#  or through the ... arguments:
param <- list(max_depth = 2, eta = 1, silent = 1, nthread = 2)
bst <- xgb.train(param, dtrain, nrounds = 2, watchlist,
                 objective = logregobj, eval_metric = evalerror)

#  or as dedicated 'obj' and 'feval' parameters of xgb.train:
bst <- xgb.train(param, dtrain, nrounds = 2, watchlist,
                 obj = logregobj, feval = evalerror)

https://github.com/dmlc/xgboost/blob/72451457120ac9d59573cf7580ccd2ad178ef908/R-package/R/xgb.train.R#L176

Deucalion answered 26/10, 2016 at 15:28 Comment(0)
L
9

feval is to create your own customized evaluation metric.

  • it must be a (custom, user-defined) function

eval_metric is for built in metrics xgboost package is implementing.

  • it's a string, e.g. rmse / logloss/ mlogloss/ merror/ error/ auc/ ndcg/ ...
Lazos answered 7/12, 2017 at 8:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.