MCPcopy Create free account
hub / github.com/dmlc/xgboost / TestBaseScore

Method TestBaseScore

tests/cpp/test_learner.cc:636–668  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

634
635class TestColumnSplit : public ::testing::TestWithParam<std::string> {
636 void TestBaseScore(std::string objective, std::vector<float> const& expected_base_score,
637 Json expected_model) {
638 auto const world_size = collective::GetWorldSize();
639 auto n_threads = collective::GetWorkerLocalThreads(world_size);
640 auto const rank = collective::GetRank();
641
642 std::shared_ptr<DMatrix> p_fmat = MakeFmatForObjTest(objective, 10, 10, 3);
643 std::shared_ptr<DMatrix> sliced{p_fmat->SliceCol(world_size, rank)};
644 std::unique_ptr<Learner> learner{Learner::Create({sliced})};
645 learner->SetParams(Args{{"nthread", std::to_string(n_threads)},
646 {"tree_method", "approx"},
647 {"objective", objective}});
648 if (objective.find("quantile") != std::string::npos) {
649 learner->SetParam("quantile_alpha", "0.5");
650 }
651 if (objective.find("expectile") != std::string::npos) {
652 learner->SetParam("expectile_alpha", "0.5");
653 }
654 if (objective.find("multi") != std::string::npos) {
655 learner->SetParam("num_class", "3");
656 }
657 learner->UpdateOneIter(0, sliced);
658 Json config{Object{}};
659 learner->SaveConfig(&config);
660 auto base_score = GetBaseScore(config);
661 for (size_t idx = 0; idx < base_score.size(); ++idx) {
662 ASSERT_NEAR(base_score[idx], expected_base_score[idx], 1e-6);
663 }
664
665 Json model{Object{}};
666 learner->SaveModel(&model);
667 CompareJsonModels(model, expected_model);
668 }
669
670 public:
671 void Run(std::string objective) {

Callers 1

RunMethod · 0.95

Calls 13

GetWorldSizeFunction · 0.85
GetWorkerLocalThreadsFunction · 0.85
GetRankFunction · 0.85
MakeFmatForObjTestFunction · 0.85
GetBaseScoreFunction · 0.85
CompareJsonModelsFunction · 0.85
SetParamsMethod · 0.80
SetParamMethod · 0.80
UpdateOneIterMethod · 0.80
SliceColMethod · 0.45
SaveConfigMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected