Skip to content

Commit

Permalink
add leaf count in ToJSON instead
Browse files Browse the repository at this point in the history
  • Loading branch information
thatlittleboy committed Jul 9, 2023
1 parent aa312fd commit 59ae704
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/io/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,20 @@ std::string Tree::ToJSON() const {
str_buf << "\"num_leaves\":" << num_leaves_ << "," << '\n';
str_buf << "\"num_cat\":" << num_cat_ << "," << '\n';
str_buf << "\"shrinkage\":" << shrinkage_ << "," << '\n';
// if (num_leaves_ == 1) {
// if (is_linear_) {
// str_buf << "\"tree_structure\":{" << "\"leaf_value\":" << leaf_value_[0] << ", " << "\n";
// str_buf << LinearModelToJSON(0) << "}" << "\n";
// } else {
// str_buf << "\"tree_structure\":{" << "\"leaf_value\":" << leaf_value_[0] << "}" << '\n';
// }
// } else {
str_buf << "\"tree_structure\":" << NodeToJSON(0) << '\n';
// }
if (num_leaves_ == 1) {
str_buf << "\"tree_structure\":{";
if (is_linear_) {
str_buf << "\"leaf_value\":" << leaf_value_[0] << ", " << '\n';
str_buf << "\"leaf_count\":" << leaf_count_[0] << ", " << '\n';
str_buf << LinearModelToJSON(0);
} else {
str_buf << "\"leaf_value\":" << leaf_value_[0] << ", " << '\n';
str_buf << "\"leaf_count\":" << leaf_count_[0];
}
str_buf << "}" << '\n';
} else {
str_buf << "\"tree_structure\":" << NodeToJSON(0) << '\n';
}
return str_buf.str();
}

Expand Down

0 comments on commit 59ae704

Please sign in to comment.