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

Function assert_constraint

tests/python-gpu/test_monotonic_constraints.py:19–36  ·  view source on GitHub ↗
(constraint: int, tree_method: str)

Source from the content-addressed store, hash-verified

17
18
19def 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())

Callers 2

test_gpu_hist_basicFunction · 0.85
test_gpu_approx_basicFunction · 0.85

Calls 6

make_regressionFunction · 0.85
non_decreasingFunction · 0.70
non_increasingFunction · 0.70
DMatrixMethod · 0.45
trainMethod · 0.45
predictMethod · 0.45

Tested by

no test coverage detected