From 81414c0e5b4fd36f56a4d445337202cb72fd2d14 Mon Sep 17 00:00:00 2001 From: tqchen Date: Tue, 29 Apr 2014 17:26:58 -0700 Subject: [PATCH] new AUC code --- regrank/xgboost_regrank.h | 1 + regrank/xgboost_regrank_eval.h | 6 ++++-- regrank/xgboost_regrank_obj.hpp | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/regrank/xgboost_regrank.h b/regrank/xgboost_regrank.h index 9482ce11e..df513ffb6 100644 --- a/regrank/xgboost_regrank.h +++ b/regrank/xgboost_regrank.h @@ -256,6 +256,7 @@ namespace xgboost{ ModelParam(void){ base_score = 0.5f; loss_type = 0; + num_feature = 0; memset(reserved, 0, sizeof(reserved)); } /*! diff --git a/regrank/xgboost_regrank_eval.h b/regrank/xgboost_regrank_eval.h index c4ff39572..7d104adf0 100644 --- a/regrank/xgboost_regrank_eval.h +++ b/regrank/xgboost_regrank_eval.h @@ -27,6 +27,8 @@ namespace xgboost{ const DMatrix::Info &info ) const = 0; /*! \return name of metric */ virtual const char *Name(void) const = 0; + /*! \brief virtual destructor */ + virtual ~IEvaluator(void){} }; /*! \brief RMSE */ @@ -104,8 +106,8 @@ namespace xgboost{ std::vector tgptr(2,0); tgptr[1] = preds.size(); const std::vector &gptr = info.group_ptr.size() == 0 ? tgptr : info.group_ptr; utils::Assert( gptr.back() == preds.size(), "EvalAuc: group structure must match number of prediction" ); - const unsigned ngroup = static_cast( gptr.size() ); - + const unsigned ngroup = static_cast( gptr.size() - 1 ); + double sum_auc = 0.0f; #pragma omp parallel reduction(+:sum_auc) { diff --git a/regrank/xgboost_regrank_obj.hpp b/regrank/xgboost_regrank_obj.hpp index b08e3f0fc..d4c000a30 100644 --- a/regrank/xgboost_regrank_obj.hpp +++ b/regrank/xgboost_regrank_obj.hpp @@ -25,8 +25,9 @@ namespace xgboost{ const unsigned ndata = static_cast(preds.size()); #pragma omp parallel for schedule( static ) for (unsigned j = 0; j < ndata; ++j){ - grad[j] = loss.FirstOrderGradient(preds[j], info.labels[j]) * info.GetWeight(j); - hess[j] = loss.SecondOrderGradient(preds[j], info.labels[j]) * info.GetWeight(j); + float p = loss.PredTransform(preds[j]); + grad[j] = loss.FirstOrderGradient(p, info.labels[j]) * info.GetWeight(j); + hess[j] = loss.SecondOrderGradient(p, info.labels[j]) * info.GetWeight(j); } } virtual const char* DefaultEvalMetric(void) {