-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Closed
Labels
Description
XGBoost version 1.0.2 installed using pip
Here's a code snippet that reproduces the error:
import xgboost as xgb
import numpy as np
import pandas as pd
import json
num_examples, num_features = 100, 5
X = np.random.randint(0, 2, size=(num_examples, num_features), dtype=bool)
pdX = pd.DataFrame(X)
y = pdX.sum(axis=1) > (num_features // 2)
clf = xgb.XGBClassifier(
max_depth=1,
learning_rate=1.0,
n_estimators=1)
model = clf.fit(pdX, y)
dump = model.get_booster().get_dump(dump_format="json")
print(dump[0])
json.loads(dump[0]) # produces JSON syntax error
output:
{ "nodeid": 0, "depth": 0, "split": "2", "yes": 2, "no": 1} , "children": [
{ "nodeid": 1, "leaf": -0.980392158 },
{ "nodeid": 2, "leaf": 0.807017565 }
]}
Traceback (most recent call last):
File "test.py", line 17, in <module>
json.loads(dump[0]) # produces JSON syntax error
File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.8/json/decoder.py", line 340, in decode
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 63 (char 62)
It's the closing brace here "no": 2 **}**
Note that this problem only occurs for binary splits.