MCPcopy Create free account
hub / github.com/dmlc/xgboost / json_model

Function json_model

tests/python/test_model_io.py:14–35  ·  view source on GitHub ↗
(model_path: str, parameters: dict)

Source from the content-addressed store, hash-verified

12
13
14def json_model(model_path: str, parameters: dict) -> dict:
15 datasets = pytest.importorskip("sklearn.datasets")
16
17 X, y = datasets.make_classification(64, n_features=8, n_classes=3, n_informative=6)
18 if parameters.get("objective", None) == "multi:softmax":
19 parameters["num_class"] = 3
20
21 dm1 = xgb.DMatrix(X, y)
22
23 bst = xgb.train(parameters, dm1)
24 bst.save_model(model_path)
25
26 if model_path.endswith("ubj"):
27 import ubjson
28
29 with open(model_path, "rb") as ubjfd:
30 model = ubjson.load(ubjfd)
31 else:
32 with open(model_path, "r") as fd:
33 model = json.load(fd)
34
35 return model
36
37
38class TestBoosterIO:

Callers 1

run_model_json_ioMethod · 0.85

Calls 5

getMethod · 0.45
DMatrixMethod · 0.45
trainMethod · 0.45
save_modelMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected