added code for instance based weighing for rank objectives (#3379)

* added code for instance based weighing for rank objectives

* Fix lint
This commit is contained in:
ngoyal2707
2018-06-22 15:10:59 -07:00
committed by Philip Hyunsu Cho
parent d062c6f61b
commit 5cd851ccef
5 changed files with 85 additions and 10 deletions

View File

@@ -0,0 +1,28 @@
// Copyright by Contributors
#include <xgboost/metric.h>
#include "../helpers.h"
TEST(Metric, MultiClassError) {
xgboost::Metric * metric = xgboost::Metric::Create("merror");
ASSERT_STREQ(metric->Name(), "merror");
EXPECT_ANY_THROW(GetMetricEval(metric, {0}, {0, 0}));
EXPECT_NEAR(GetMetricEval(
metric, {1, 0, 0, 0, 1, 0, 0, 0, 1}, {0, 1, 2}), 0, 1e-10);
EXPECT_NEAR(GetMetricEval(metric,
{0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f},
{0, 1, 2}),
0.666f, 0.001f);
}
TEST(Metric, MultiClassLogLoss) {
xgboost::Metric * metric = xgboost::Metric::Create("mlogloss");
ASSERT_STREQ(metric->Name(), "mlogloss");
EXPECT_ANY_THROW(GetMetricEval(metric, {0}, {0, 0}));
EXPECT_NEAR(GetMetricEval(
metric, {1, 0, 0, 0, 1, 0, 0, 0, 1}, {0, 1, 2}), 0, 1e-10);
EXPECT_NEAR(GetMetricEval(metric,
{0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f},
{0, 1, 2}),
2.302f, 0.001f);
}