Skip to content

Commit

Permalink
Fix tweedie handling of base_score (dmlc#3295)
Browse files Browse the repository at this point in the history
* fix tweedie margin calculations

* add entry to contributors
  • Loading branch information
pdesahb authored and hcho3 committed Jun 28, 2018
1 parent 64b8cff commit 12e34f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ List of Contributors
* [Andrew Hannigan](https://github.com/andrewhannigan)
* [Andy Adinets](https://github.com/canonizer)
* [Henry Gouk](https://github.com/henrygouk)
* [Pierre de Sahb](https://github.com/pdesahb)
5 changes: 5 additions & 0 deletions src/objective/regression_obj.cc
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ class TweedieRegression : public ObjFunction {
preds[j] = std::exp(preds[j]);
}
}

bst_float ProbToMargin(bst_float base_score) const override {
return std::log(base_score);
}

const char* DefaultEvalMetric() const override {
std::ostringstream os;
os << "tweedie-nloglik@" << param_.tweedie_variance_power;
Expand Down
6 changes: 3 additions & 3 deletions tests/cpp/objective/test_regression_obj.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ TEST(Objective, TweedieRegressionBasic) {
<< "Expected error when label < 0 for TweedieRegression";

// test ProbToMargin
EXPECT_NEAR(obj->ProbToMargin(0.1f), 0.10f, 0.01f);
EXPECT_NEAR(obj->ProbToMargin(0.5f), 0.5f, 0.01f);
EXPECT_NEAR(obj->ProbToMargin(0.9f), 0.89f, 0.01f);
EXPECT_NEAR(obj->ProbToMargin(0.1f), -2.30f, 0.01f);
EXPECT_NEAR(obj->ProbToMargin(0.5f), -0.69f, 0.01f);
EXPECT_NEAR(obj->ProbToMargin(0.9f), -0.10f, 0.01f);

// test PredTransform
xgboost::HostDeviceVector<xgboost::bst_float> io_preds = {0, 0.1f, 0.5f, 0.9f, 1};
Expand Down

0 comments on commit 12e34f3

Please sign in to comment.