| 101 | } |
| 102 | |
| 103 | void 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 | |
| 131 | void TestsLogisticRawGPair(const Context* ctx) { |
| 132 | std::string obj_name = "binary:logitraw"; |
no test coverage detected