From bd01acdfbc79de2431324ab115ffca48f5d29909 Mon Sep 17 00:00:00 2001 From: Philip Hyunsu Cho Date: Sun, 3 Jun 2018 14:15:47 -0700 Subject: [PATCH] Save outputs in high precision in CLI prediction (#3356) Currently, `CLIPredict()` saves prediction results in default 6-digit precision which causes precision loss. This PR sets precision to a level so that the conversion back to `bst_float` is lossless. Related: #3298. --- src/cli_main.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cli_main.cc b/src/cli_main.cc index 068cf0de4..1bb39aaf0 100644 --- a/src/cli_main.cc +++ b/src/cli_main.cc @@ -333,7 +333,8 @@ void CLIPredict(const CLIParam& param) { dmlc::Stream::Create(param.name_pred.c_str(), "w")); dmlc::ostream os(fo.get()); for (bst_float p : preds.HostVector()) { - os << p << '\n'; + os << std::setprecision(std::numeric_limits::max_digits10 + 2) + << p << '\n'; } // force flush before fo destruct. os.set_stream(nullptr);