| 125 | } |
| 126 | |
| 127 | void GBDT::AddValidDataset(const Dataset* valid_data, |
| 128 | const std::vector<const Metric*>& valid_metrics) { |
| 129 | if (!train_data_->CheckAlign(*valid_data)) { |
| 130 | Log::Fatal("Cannot add validation data, since it has different bin mappers with training data"); |
| 131 | } |
| 132 | // for a validation dataset, we need its score and metric |
| 133 | auto new_score_updater = std::unique_ptr<ScoreUpdater>(new ScoreUpdater(valid_data, num_tree_per_iteration_, num_labels_)); |
| 134 | // update score |
| 135 | for (int i = 0; i < iter_; ++i) { |
| 136 | for (int cur_tree_id = 0; cur_tree_id < num_tree_per_iteration_; ++cur_tree_id) { |
| 137 | auto curr_tree = (i + num_init_iteration_) * num_tree_per_iteration_ + cur_tree_id; |
| 138 | new_score_updater->AddScore(models_[curr_tree].get(), cur_tree_id); |
| 139 | } |
| 140 | } |
| 141 | valid_score_updater_.push_back(std::move(new_score_updater)); |
| 142 | valid_metrics_.emplace_back(); |
| 143 | for (const auto& metric : valid_metrics) { |
| 144 | valid_metrics_.back().push_back(metric); |
| 145 | } |
| 146 | valid_metrics_.back().shrink_to_fit(); |
| 147 | |
| 148 | if (early_stopping_round_ > 0) { |
| 149 | auto num_metrics = valid_metrics.size(); |
| 150 | if (es_first_metric_only_) { num_metrics = 1; } |
| 151 | best_iter_.emplace_back(num_metrics, 0); |
| 152 | best_score_.emplace_back(num_metrics, kMinScore); |
| 153 | best_msg_.emplace_back(num_metrics); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | void GBDT::Boosting() { |
| 158 | if (objective_function_ == nullptr) { |
no test coverage detected