MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / Booster

Class Booster

python-package/compile/src/c_api.cpp:98–432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96};
97
98class Booster {
99 public:
100 explicit Booster(const char* filename) {
101 boosting_.reset(Boosting::CreateBoosting("gbdt", filename));
102 }
103
104 Booster(const Dataset* train_data,
105 const char* parameters) {
106 auto param = Config::Str2Map(parameters);
107 config_.Set(param);
108 if (config_.num_threads > 0) {
109 omp_set_num_threads(config_.num_threads);
110 }
111 // create boosting
112 if (config_.input_model.size() > 0) {
113 Log::Warning("Continued train from model is not supported for c_api,\n"
114 "please use continued train with input score");
115 }
116
117 boosting_.reset(Boosting::CreateBoosting(config_.boosting, nullptr));
118 train_data_ = train_data;
119 CreateObjectiveAndMetrics();
120 // initialize the boosting
121 if (config_.tree_learner == std::string("feature")) {
122 Log::Fatal("Do not support feature parallel in c api");
123 }
124 if (Network::num_machines() == 1 && config_.tree_learner != std::string("serial") && config_.tree_learner != std::string("serial2")) {
125 Log::Warning("Only find one worker, will switch to serial tree learner");
126 config_.tree_learner = "serial";
127 }
128 boosting_->Init(&config_, train_data_, objective_fun_.get(),
129 Common::ConstPtrInVectorWrapper<Metric>(train_metric_));
130 }
131
132 void MergeFrom(const Booster* other) {
133 std::lock_guard<std::mutex> lock(mutex_);
134 boosting_->MergeFrom(other->boosting_.get());
135 }
136
137 ~Booster() {
138 }
139
140 void CreateObjectiveAndMetrics() {
141 // create objective function
142 objective_fun_.reset(ObjectiveFunction::CreateObjectiveFunction(config_.objective,
143 config_));
144 if (objective_fun_ == nullptr) {
145 Log::Warning("Using self-defined objective function");
146 }
147 // initialize the objective function
148 if (objective_fun_ != nullptr) {
149 objective_fun_->Init(train_data_->metadata(), train_data_->num_data());
150 }
151
152 // create training metric
153 train_metric_.clear();
154 for (auto metric_type : config_.metric) {
155 auto metric = std::unique_ptr<Metric>(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected