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

Function TestLogisticRegressionBasic

tests/cpp/objective/test_regression_obj.cc:103–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103void TestLogisticRegressionBasic(const Context* ctx) {
104 std::string obj_name = "reg:logistic";
105 std::vector<std::pair<std::string, std::string>> args;
106 std::unique_ptr<ObjFunction> obj{ObjFunction::Create(obj_name, ctx)};
107
108 obj->Configure(args);
109 CheckConfigReload(obj, obj_name);
110
111 // test label validation
112 EXPECT_ANY_THROW(CheckObjFunction(obj, {0}, {10}, {1}, {0}, {0}))
113 << "Expected error when label not in range [0,1f] for LogisticRegression";
114
115 // test ProbToMargin
116 CheckProbaToMargin(obj, 0.1f, -2.197f);
117 CheckProbaToMargin(obj, 0.5f, 0);
118 CheckProbaToMargin(obj, 0.9f, 2.197f);
119 ASSERT_THAT([&] { CheckProbaToMargin(obj, 10, 0); }, GMockThrow("base_score must be in (0,1)"));
120
121 // test PredTransform
122 HostDeviceVector<bst_float> io_preds = {0, 0.1f, 0.5f, 0.9f, 1};
123 std::vector<bst_float> out_preds = {0.5f, 0.524f, 0.622f, 0.710f, 0.731f};
124 obj->PredTransform(&io_preds);
125 auto& preds = io_preds.HostVector();
126 for (int i = 0; i < static_cast<int>(io_preds.Size()); ++i) {
127 EXPECT_NEAR(preds[i], out_preds[i], 0.01f);
128 }
129}
130
131void TestsLogisticRawGPair(const Context* ctx) {
132 std::string obj_name = "binary:logitraw";

Callers 2

TESTFunction · 0.85
TESTFunction · 0.85

Calls 7

CheckConfigReloadFunction · 0.85
CheckObjFunctionFunction · 0.85
CheckProbaToMarginFunction · 0.85
GMockThrowFunction · 0.85
ConfigureMethod · 0.45
PredTransformMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected