| 212 | } |
| 213 | |
| 214 | void Application::Predict() { |
| 215 | if (config_.task == TaskType::KRefitTree) { |
| 216 | // create predictor |
| 217 | Predictor predictor(boosting_.get(), -1, false, true, false, false, 1, 1); |
| 218 | predictor.Predict(config_.data.c_str(), config_.output_result.c_str(), config_.header); |
| 219 | TextReader<int> result_reader(config_.output_result.c_str(), false); |
| 220 | result_reader.ReadAllLines(); |
| 221 | std::vector<std::vector<int>> pred_leaf(result_reader.Lines().size()); |
| 222 | #pragma omp parallel for schedule(static) |
| 223 | for (int i = 0; i < static_cast<int>(result_reader.Lines().size()); ++i) { |
| 224 | pred_leaf[i] = Common::StringToArray<int>(result_reader.Lines()[i], '\t'); |
| 225 | // Free memory |
| 226 | result_reader.Lines()[i].clear(); |
| 227 | } |
| 228 | DatasetLoader dataset_loader(config_, nullptr, |
| 229 | config_.num_class, config_.data.c_str()); |
| 230 | train_data_.reset(dataset_loader.LoadFromFile(config_.data.c_str(), config_.initscore_filename.c_str(), |
| 231 | 0, 1)); |
| 232 | train_metric_.clear(); |
| 233 | objective_fun_.reset(ObjectiveFunction::CreateObjectiveFunction(config_.objective, |
| 234 | config_)); |
| 235 | objective_fun_->Init(train_data_->metadata(), train_data_->num_data()); |
| 236 | boosting_->Init(&config_, train_data_.get(), objective_fun_.get(), |
| 237 | Common::ConstPtrInVectorWrapper<Metric>(train_metric_)); |
| 238 | boosting_->RefitTree(pred_leaf); |
| 239 | boosting_->SaveModelToFile(0, -1, config_.output_model.c_str()); |
| 240 | Log::Info("Finished RefitTree"); |
| 241 | } else { |
| 242 | // create predictor |
| 243 | Predictor predictor(boosting_.get(), config_.num_iteration_predict, config_.predict_raw_score, |
| 244 | config_.predict_leaf_index, config_.predict_contrib, |
| 245 | config_.pred_early_stop, config_.pred_early_stop_freq, |
| 246 | config_.pred_early_stop_margin); |
| 247 | predictor.Predict(config_.data.c_str(), |
| 248 | config_.output_result.c_str(), config_.header); |
| 249 | Log::Info("Finished prediction"); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | void Application::InitPredict() { |
| 254 | boosting_.reset( |
nothing calls this directly
no test coverage detected