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

Method DumpModel

src/boosting/gbdt_model_text.cpp:20–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18const char* kModelVersion = "v3";
19
20std::string GBDT::DumpModel(int start_iteration, int num_iteration) const {
21 std::stringstream str_buf;
22
23 str_buf << "{";
24 str_buf << "\"name\":\"" << SubModelName() << "\"," << '\n';
25 str_buf << "\"version\":\"" << kModelVersion << "\"," << '\n';
26 str_buf << "\"num_class\":" << num_class_ << "," << '\n';
27 str_buf << "\"num_tree_per_iteration\":" << num_tree_per_iteration_ << "," << '\n';
28 str_buf << "\"label_index\":" << label_idx_ << "," << '\n';
29 str_buf << "\"max_feature_idx\":" << max_feature_idx_ << "," << '\n';
30 str_buf << "\"average_output\":" << (average_output_ ? "true" : "false") << ",\n";
31 if (objective_function_ != nullptr) {
32 str_buf << "\"objective\":\"" << objective_function_->ToString() << "\",\n";
33 }
34
35 str_buf << "\"feature_names\":[\"" << Common::Join(feature_names_, "\",\"")
36 << "\"]," << '\n';
37
38 str_buf << "\"monotone_constraints\":["
39 << Common::Join(monotone_constraints_, ",") << "]," << '\n';
40
41 str_buf << "\"tree_info\":[";
42 int num_used_model = static_cast<int>(models_.size());
43 int total_iteration = num_used_model / num_tree_per_iteration_;
44 start_iteration = std::max(start_iteration, 0);
45 start_iteration = std::min(start_iteration, total_iteration);
46 if (num_iteration > 0) {
47 int end_iteration = start_iteration + num_iteration;
48 num_used_model = std::min(end_iteration * num_tree_per_iteration_ , num_used_model);
49 }
50 int start_model = start_iteration * num_tree_per_iteration_;
51 for (int i = start_model; i < num_used_model; ++i) {
52 if (i > start_model) {
53 str_buf << ",";
54 }
55 str_buf << "{";
56 str_buf << "\"tree_index\":" << i << ",";
57 str_buf << models_[i]->ToJSON();
58 str_buf << "}";
59 }
60 str_buf << "]" << '\n';
61
62 str_buf << "}" << '\n';
63
64 return str_buf.str();
65}
66
67std::string GBDT::ModelToIfElse(int num_iteration) const {
68 std::stringstream str_buf;

Callers

nothing calls this directly

Calls 4

JoinFunction · 0.50
ToStringMethod · 0.45
sizeMethod · 0.45
ToJSONMethod · 0.45

Tested by

no test coverage detected