Increase precision of bst_float values in tree dumps (#3298)
* Increase precision of bst_float values in tree dumps * Increase precision of bst_float values in tree dumps * Fix lint error and switch precision to right float variable * Fix clang-tidy error
This commit is contained in:
parent
d13f1a0f16
commit
cc79a65ab9
@ -5,6 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
#include <xgboost/tree_model.h>
|
#include <xgboost/tree_model.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <limits>
|
||||||
|
#include <iomanip>
|
||||||
#include "./param.h"
|
#include "./param.h"
|
||||||
|
|
||||||
namespace xgboost {
|
namespace xgboost {
|
||||||
@ -20,6 +22,7 @@ void DumpRegTree(std::stringstream& fo, // NOLINT(*)
|
|||||||
const FeatureMap& fmap,
|
const FeatureMap& fmap,
|
||||||
int nid, int depth, int add_comma,
|
int nid, int depth, int add_comma,
|
||||||
bool with_stats, std::string format) {
|
bool with_stats, std::string format) {
|
||||||
|
int float_max_precision = std::numeric_limits<bst_float>::max_digits10;
|
||||||
if (format == "json") {
|
if (format == "json") {
|
||||||
if (add_comma) {
|
if (add_comma) {
|
||||||
fo << ",";
|
fo << ",";
|
||||||
@ -38,15 +41,15 @@ void DumpRegTree(std::stringstream& fo, // NOLINT(*)
|
|||||||
if (tree[nid].IsLeaf()) {
|
if (tree[nid].IsLeaf()) {
|
||||||
if (format == "json") {
|
if (format == "json") {
|
||||||
fo << "{ \"nodeid\": " << nid
|
fo << "{ \"nodeid\": " << nid
|
||||||
<< ", \"leaf\": " << tree[nid].LeafValue();
|
<< ", \"leaf\": " << std::setprecision(float_max_precision) << tree[nid].LeafValue();
|
||||||
if (with_stats) {
|
if (with_stats) {
|
||||||
fo << ", \"cover\": " << tree.Stat(nid).sum_hess;
|
fo << ", \"cover\": " << std::setprecision(float_max_precision) << tree.Stat(nid).sum_hess;
|
||||||
}
|
}
|
||||||
fo << " }";
|
fo << " }";
|
||||||
} else {
|
} else {
|
||||||
fo << nid << ":leaf=" << tree[nid].LeafValue();
|
fo << nid << ":leaf=" << std::setprecision(float_max_precision) << tree[nid].LeafValue();
|
||||||
if (with_stats) {
|
if (with_stats) {
|
||||||
fo << ",cover=" << tree.Stat(nid).sum_hess;
|
fo << ",cover=" << std::setprecision(float_max_precision) << tree.Stat(nid).sum_hess;
|
||||||
}
|
}
|
||||||
fo << '\n';
|
fo << '\n';
|
||||||
}
|
}
|
||||||
@ -95,12 +98,13 @@ void DumpRegTree(std::stringstream& fo, // NOLINT(*)
|
|||||||
fo << "{ \"nodeid\": " << nid
|
fo << "{ \"nodeid\": " << nid
|
||||||
<< ", \"depth\": " << depth
|
<< ", \"depth\": " << depth
|
||||||
<< ", \"split\": \"" << fmap.Name(split_index) << "\""
|
<< ", \"split\": \"" << fmap.Name(split_index) << "\""
|
||||||
<< ", \"split_condition\": " << cond
|
<< ", \"split_condition\": " << std::setprecision(float_max_precision) << cond
|
||||||
<< ", \"yes\": " << tree[nid].LeftChild()
|
<< ", \"yes\": " << tree[nid].LeftChild()
|
||||||
<< ", \"no\": " << tree[nid].RightChild()
|
<< ", \"no\": " << tree[nid].RightChild()
|
||||||
<< ", \"missing\": " << tree[nid].DefaultChild();
|
<< ", \"missing\": " << tree[nid].DefaultChild();
|
||||||
} else {
|
} else {
|
||||||
fo << nid << ":[" << fmap.Name(split_index) << "<" << cond
|
fo << nid << ":[" << fmap.Name(split_index)
|
||||||
|
<< "<" << std::setprecision(float_max_precision) << cond
|
||||||
<< "] yes=" << tree[nid].LeftChild()
|
<< "] yes=" << tree[nid].LeftChild()
|
||||||
<< ",no=" << tree[nid].RightChild()
|
<< ",no=" << tree[nid].RightChild()
|
||||||
<< ",missing=" << tree[nid].DefaultChild();
|
<< ",missing=" << tree[nid].DefaultChild();
|
||||||
@ -114,12 +118,12 @@ void DumpRegTree(std::stringstream& fo, // NOLINT(*)
|
|||||||
fo << "{ \"nodeid\": " << nid
|
fo << "{ \"nodeid\": " << nid
|
||||||
<< ", \"depth\": " << depth
|
<< ", \"depth\": " << depth
|
||||||
<< ", \"split\": " << split_index
|
<< ", \"split\": " << split_index
|
||||||
<< ", \"split_condition\": " << cond
|
<< ", \"split_condition\": " << std::setprecision(float_max_precision) << cond
|
||||||
<< ", \"yes\": " << tree[nid].LeftChild()
|
<< ", \"yes\": " << tree[nid].LeftChild()
|
||||||
<< ", \"no\": " << tree[nid].RightChild()
|
<< ", \"no\": " << tree[nid].RightChild()
|
||||||
<< ", \"missing\": " << tree[nid].DefaultChild();
|
<< ", \"missing\": " << tree[nid].DefaultChild();
|
||||||
} else {
|
} else {
|
||||||
fo << nid << ":[f" << split_index << "<"<< cond
|
fo << nid << ":[f" << split_index << "<"<< std::setprecision(float_max_precision) << cond
|
||||||
<< "] yes=" << tree[nid].LeftChild()
|
<< "] yes=" << tree[nid].LeftChild()
|
||||||
<< ",no=" << tree[nid].RightChild()
|
<< ",no=" << tree[nid].RightChild()
|
||||||
<< ",missing=" << tree[nid].DefaultChild();
|
<< ",missing=" << tree[nid].DefaultChild();
|
||||||
@ -127,10 +131,11 @@ void DumpRegTree(std::stringstream& fo, // NOLINT(*)
|
|||||||
}
|
}
|
||||||
if (with_stats) {
|
if (with_stats) {
|
||||||
if (format == "json") {
|
if (format == "json") {
|
||||||
fo << ", \"gain\": " << tree.Stat(nid).loss_chg
|
fo << ", \"gain\": " << std::setprecision(float_max_precision) << tree.Stat(nid).loss_chg
|
||||||
<< ", \"cover\": " << tree.Stat(nid).sum_hess;
|
<< ", \"cover\": " << std::setprecision(float_max_precision) << tree.Stat(nid).sum_hess;
|
||||||
} else {
|
} else {
|
||||||
fo << ",gain=" << tree.Stat(nid).loss_chg << ",cover=" << tree.Stat(nid).sum_hess;
|
fo << ",gain=" << std::setprecision(float_max_precision) << tree.Stat(nid).loss_chg
|
||||||
|
<< ",cover=" << std::setprecision(float_max_precision) << tree.Stat(nid).sum_hess;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (format == "json") {
|
if (format == "json") {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user