Calculate base_score based on input labels for mae. (#8107)
Fit an intercept as base score for abs loss.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user