Calculate base_score based on input labels for mae. (#8107)

Fit an intercept as base score for abs loss.
This commit is contained in:
Jiaming Yuan
2022-09-20 20:53:54 +08:00
committed by GitHub
parent 4f42aa5f12
commit fffb1fca52
42 changed files with 999 additions and 343 deletions

View File

@@ -29,5 +29,15 @@ TEST(Numeric, PartialSum) {
ASSERT_EQ(sol, result);
}
}
TEST(Numeric, Reduce) {
Context ctx;
ASSERT_TRUE(ctx.IsCPU());
HostDeviceVector<float> values(20);
auto& h_values = values.HostVector();
std::iota(h_values.begin(), h_values.end(), 0.0f);
auto sum = Reduce(&ctx, values);
ASSERT_EQ(sum, (values.Size() - 1) * values.Size() / 2);
}
} // namespace common
} // namespace xgboost

View File

@@ -54,5 +54,20 @@ TEST(Stats, WeightedQuantile) {
q = WeightedQuantile(1.0, beg, end, w);
ASSERT_EQ(q, 5);
}
TEST(Stats, Median) {
linalg::Tensor<float, 2> values{{.0f, .0f, 1.f, 2.f}, {4}, Context::kCpuId};
Context ctx;
HostDeviceVector<float> weights;
auto m = Median(&ctx, values, weights);
ASSERT_EQ(m, .5f);
#if defined(XGBOOST_USE_CUDA)
ctx.gpu_id = 0;
ASSERT_FALSE(ctx.IsCPU());
m = Median(&ctx, values, weights);
ASSERT_EQ(m, .5f);
#endif // defined(XGBOOST_USE_CUDA)
}
} // namespace common
} // namespace xgboost