Add rmsle metric and reg:squaredlogerror objective (#4541)

This commit is contained in:
Jiaming Yuan
2019-06-11 05:48:27 +08:00
committed by GitHub
parent 9683fd433e
commit 2f1319f273
7 changed files with 92 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
/*!
* Copyright 2017 XGBoost contributors
* Copyright 2017-2019 XGBoost contributors
*/
#ifndef XGBOOST_OBJECTIVE_REGRESSION_LOSS_H_
#define XGBOOST_OBJECTIVE_REGRESSION_LOSS_H_
@@ -36,6 +36,29 @@ struct LinearSquareLoss {
static const char* DefaultEvalMetric() { return "rmse"; }
};
struct SquaredLogError {
XGBOOST_DEVICE static bst_float PredTransform(bst_float x) { return x; }
XGBOOST_DEVICE static bool CheckLabel(bst_float label) {
return label > -1;
}
XGBOOST_DEVICE static bst_float FirstOrderGradient(bst_float predt, bst_float label) {
predt = fmaxf(predt, -1 + 1e-6); // ensure correct value for log1p
return (std::log1p(predt) - std::log1p(label)) / (predt + 1);
}
XGBOOST_DEVICE static bst_float SecondOrderGradient(bst_float predt, bst_float label) {
predt = fmaxf(predt, -1 + 1e-6);
float res = (-std::log1p(predt) + std::log1p(label) + 1) /
std::pow(predt + 1, 2);
res = fmaxf(res, 1e-6f);
return res;
}
static bst_float ProbToMargin(bst_float base_score) { return base_score; }
static const char* LabelErrorMsg() {
return "label must be greater than -1 for rmsle so that log(label + 1) can be valid.";
}
static const char* DefaultEvalMetric() { return "rmsle"; }
};
// logistic loss for probability regression task
struct LogisticRegression {
// duplication is necessary, as __device__ specifier