| 286 | } |
| 287 | |
| 288 | void GBDT::Train(int snapshot_freq, const std::string& model_output_path) { |
| 289 | bool is_finished = false; |
| 290 | auto start_time = std::chrono::steady_clock::now(); |
| 291 | for (int iter = 0; iter < config_->num_iterations && !is_finished; ++iter) { |
| 292 | is_finished = TrainOneIter(nullptr, nullptr); |
| 293 | if (!is_finished) { |
| 294 | is_finished = EvalAndCheckEarlyStopping(); |
| 295 | } |
| 296 | auto end_time = std::chrono::steady_clock::now(); |
| 297 | // output used time per iteration |
| 298 | Log::Info("%f seconds elapsed, finished iteration %d", std::chrono::duration<double, |
| 299 | std::milli>(end_time - start_time) * 1e-3, iter + 1); |
| 300 | if (snapshot_freq > 0 |
| 301 | && (iter + 1) % snapshot_freq == 0) { |
| 302 | std::string snapshot_out = model_output_path + ".snapshot_iter_" + std::to_string(iter + 1); |
| 303 | SaveModelToFile(0, -1, snapshot_out.c_str()); |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | void GBDT::RefitTree(const std::vector<std::vector<int>>& tree_leaf_prediction) { |
| 309 | CHECK(tree_leaf_prediction.size() > 0); |
no test coverage detected