【问题标题】:What is difference between eval_metric and feval in xgboost?xgboost 中的 eval_metric 和 feval 有什么区别?
【发布时间】:2017-03-02 17:57:04
【问题描述】:

xgb.train 中的fevaleval_metric 有什么区别,这两个参数仅用于评估目的。

来自 Kaggle 的帖子提供了一些见解:

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

【问题讨论】:

    标签: r xgboost kaggle


    【解决方案1】:

    feval 是创建您自己的自定义评估指标。

    • 它必须是(自定义的、用户定义的)函数

    eval_metric 用于 xgboost 包正在实施的内置指标。

    • 它是一个字符串,例如rmse / logloss/ mlogloss/ merror/ error/ auc/ ndcg/ ...

    【讨论】:

      【解决方案2】:

      他们都做大致相同的事情。

      Eval_metric 可以采用字符串(使用其内部函数)或用户定义的函数

      feval 只接受一个函数

      正如您所说,两者都是出于评估目的。

      在下面的示例中,您可以看到它们的用法非常相似。

      ## 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

      【讨论】:

        猜你喜欢
        • 2016-03-14
        • 2016-05-16
        • 2022-10-14
        • 2020-10-02
        • 1970-01-01
        • 1970-01-01
        • 2018-12-22
        • 2018-08-19
        • 2021-09-06
        相关资源
        最近更新 更多