Tests for dask skl categorical data support. (#7054)

This commit is contained in:
Jiaming Yuan
2021-06-24 16:33:57 +08:00
committed by GitHub
parent da1ad798ca
commit 1d4d345634
2 changed files with 33 additions and 13 deletions

View File

@@ -211,20 +211,34 @@ def test_categorical(local_cuda_cluster: LocalCUDACluster) -> None:
)
assert tm.non_increasing(by_builtin_results["Train"]["rmse"])
model = output["booster"]
with tempfile.TemporaryDirectory() as tempdir:
path = os.path.join(tempdir, "model.json")
model.save_model(path)
with open(path, "r") as fd:
categorical = json.load(fd)
def check_model_output(model: dxgb.Booster) -> None:
with tempfile.TemporaryDirectory() as tempdir:
path = os.path.join(tempdir, "model.json")
model.save_model(path)
with open(path, "r") as fd:
categorical = json.load(fd)
categories_sizes = np.array(
categorical["learner"]["gradient_booster"]["model"]["trees"][-1][
"categories_sizes"
]
)
assert categories_sizes.shape[0] != 0
np.testing.assert_allclose(categories_sizes, 1)
categories_sizes = np.array(
categorical["learner"]["gradient_booster"]["model"]["trees"][-1][
"categories_sizes"
]
)
assert categories_sizes.shape[0] != 0
np.testing.assert_allclose(categories_sizes, 1)
check_model_output(output["booster"])
reg = dxgb.DaskXGBRegressor(
enable_categorical=True, n_estimators=10, tree_method="gpu_hist"
)
reg.fit(X, y)
check_model_output(reg.get_booster())
reg = dxgb.DaskXGBRegressor(
enable_categorical=True, n_estimators=10
)
with pytest.raises(ValueError):
reg.fit(X, y)
def to_cp(x: Any, DMatrixT: Type) -> Any: