Save Scikit-Learn attributes into learner attributes. (#5245)

* Remove the recommendation for pickle.

* Save skl attributes in booster.attr

* Test loading scikit-learn model with native booster.
This commit is contained in:
Jiaming Yuan
2020-01-30 16:00:18 +08:00
committed by GitHub
parent c67163250e
commit 472ded549d
8 changed files with 194 additions and 57 deletions

View File

@@ -1,6 +1,7 @@
/*!
* Copyright (c) by Contributors 2019
*/
#include <cctype>
#include <sstream>
#include <limits>
#include <cmath>
@@ -351,7 +352,9 @@ Json JsonReader::Parse() {
return ParseObject();
} else if ( c == '[' ) {
return ParseArray();
} else if ( c == '-' || std::isdigit(c) ) {
} else if ( c == '-' || std::isdigit(c) ||
c == 'N' ) {
// For now we only accept `NaN`, not `nan` as the later violiates LR(1) with `null`.
return ParseNumber();
} else if ( c == '\"' ) {
return ParseString();
@@ -547,6 +550,13 @@ Json JsonReader::ParseNumber() {
// TODO(trivialfis): Add back all the checks for number
bool negative = false;
if (XGBOOST_EXPECT(*p == 'N', false)) {
GetChar('N');
GetChar('a');
GetChar('N');
return Json(static_cast<Number::Float>(std::numeric_limits<float>::quiet_NaN()));
}
if ('-' == *p) {
++p;
negative = true;