(model_path: str, parameters: dict)
| 12 | |
| 13 | |
| 14 | def 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 | |
| 38 | class TestBoosterIO: |
no test coverage detected