(constraint: int, tree_method: str)
| 17 | |
| 18 | |
| 19 | def assert_constraint(constraint: int, tree_method: str) -> None: |
| 20 | from sklearn.datasets import make_regression |
| 21 | |
| 22 | n = 1000 |
| 23 | X, y = make_regression(n, random_state=rng, n_features=1, n_informative=1) |
| 24 | dtrain = xgb.DMatrix(X, y) |
| 25 | param = {} |
| 26 | param["tree_method"] = tree_method |
| 27 | param["device"] = "cuda" |
| 28 | param["monotone_constraints"] = "(" + str(constraint) + ")" |
| 29 | bst = xgb.train(param, dtrain) |
| 30 | dpredict = xgb.DMatrix(X[X[:, 0].argsort()]) |
| 31 | pred = bst.predict(dpredict) |
| 32 | |
| 33 | if constraint > 0: |
| 34 | assert non_decreasing(pred) |
| 35 | elif constraint < 0: |
| 36 | assert non_increasing(pred) |
| 37 | |
| 38 | |
| 39 | @pytest.mark.skipif(**tm.no_sklearn()) |
no test coverage detected