Fix #3702: do not round up integer thresholds for integer features in JSON dump (#3717)

This commit is contained in:
Philip Hyunsu Cho 2018-09-21 01:11:21 -07:00 committed by GitHub
parent aa53e9fc8d
commit 73140ce84c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@
#include <xgboost/tree_model.h>
#include <sstream>
#include <limits>
#include <cmath>
#include <iomanip>
#include "./param.h"
@ -75,17 +76,21 @@ void DumpRegTree(std::stringstream& fo, // NOLINT(*)
break;
}
case FeatureMap::kInteger: {
const bst_float floored = std::floor(cond);
const int integer_threshold
= (floored == cond) ? static_cast<int>(floored)
: static_cast<int>(floored) + 1;
if (format == "json") {
fo << "{ \"nodeid\": " << nid
<< ", \"depth\": " << depth
<< ", \"split\": \"" << fmap.Name(split_index) << "\""
<< ", \"split_condition\": " << int(cond + 1.0)
<< ", \"split_condition\": " << integer_threshold
<< ", \"yes\": " << tree[nid].LeftChild()
<< ", \"no\": " << tree[nid].RightChild()
<< ", \"missing\": " << tree[nid].DefaultChild();
} else {
fo << nid << ":[" << fmap.Name(split_index) << "<"
<< int(cond + 1.0)
<< integer_threshold
<< "] yes=" << tree[nid].LeftChild()
<< ",no=" << tree[nid].RightChild()
<< ",missing=" << tree[nid].DefaultChild();