Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
c738c83b
Unverified
Commit
c738c83b
authored
Jun 15, 2021
by
Nikita Titov
Committed by
GitHub
Jun 15, 2021
Browse files
[tests] replace pytest.parametrize (#4377)
* replace pytest.parametrize * add informative message for assert
parent
a592316a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
9 deletions
+12
-9
tests/python_package_test/test_engine.py
tests/python_package_test/test_engine.py
+12
-9
No files found.
tests/python_package_test/test_engine.py
View file @
c738c83b
...
@@ -1252,8 +1252,8 @@ def generate_trainset_for_monotone_constraints_tests(x3_to_category=True):
...
@@ -1252,8 +1252,8 @@ def generate_trainset_for_monotone_constraints_tests(x3_to_category=True):
return trainset
return trainset
@
pytest
.
mark
.
parametrize
(
"test_with_
interaction_constraints
"
,
[
True
,
False
])
@pytest.mark.parametrize("test_with_
categorical_variable
", [True, False])
def
test_monotone_constraints
(
test_with_
interaction_constraints
):
def test_monotone_constraints(test_with_
categorical_variable
):
def is_increasing(y):
def is_increasing(y):
return (np.diff(y) >= 0.0).all()
return (np.diff(y) >= 0.0).all()
...
@@ -1316,10 +1316,12 @@ def test_monotone_constraints(test_with_interaction_constraints):
...
@@ -1316,10 +1316,12 @@ def test_monotone_constraints(test_with_interaction_constraints):
return not has_interaction_flag.any()
return not has_interaction_flag.any()
for
test_with_categorical_variable
in
[
True
,
False
]:
trainset = generate_trainset_for_monotone_constraints_tests(
trainset
=
generate_trainset_for_monotone_constraints_tests
(
test_with_categorical_variable
test_with_categorical_variable
)
)
for test_with_interaction_constraints in [True, False]:
error_msg = ("Model not correctly constrained "
f"(test_with_interaction_constraints={test_with_interaction_constraints})")
for monotone_constraints_method in ["basic", "intermediate", "advanced"]:
for monotone_constraints_method in ["basic", "intermediate", "advanced"]:
params = {
params = {
"min_data": 20,
"min_data": 20,
...
@@ -1333,7 +1335,7 @@ def test_monotone_constraints(test_with_interaction_constraints):
...
@@ -1333,7 +1335,7 @@ def test_monotone_constraints(test_with_interaction_constraints):
constrained_model = lgb.train(params, trainset)
constrained_model = lgb.train(params, trainset)
assert is_correctly_constrained(
assert is_correctly_constrained(
constrained_model, test_with_categorical_variable
constrained_model, test_with_categorical_variable
)
)
, error_msg
if test_with_interaction_constraints:
if test_with_interaction_constraints:
feature_sets = [["Column_0"], ["Column_1"], "Column_2"]
feature_sets = [["Column_0"], ["Column_1"], "Column_2"]
assert are_interactions_enforced(constrained_model, feature_sets)
assert are_interactions_enforced(constrained_model, feature_sets)
...
@@ -1399,8 +1401,9 @@ def test_monotone_penalty_max():
...
@@ -1399,8 +1401,9 @@ def test_monotone_penalty_max():
}
}
unconstrained_model = lgb.train(params_unconstrained_model, trainset_unconstrained_model, 10)
unconstrained_model = lgb.train(params_unconstrained_model, trainset_unconstrained_model, 10)
unconstrained_model_predictions
=
unconstrained_model
.
\
unconstrained_model_predictions = unconstrained_model.predict(
predict
(
x3_negatively_correlated_with_y
.
reshape
(
-
1
,
1
))
x3_negatively_correlated_with_y.reshape(-1, 1)
)
for monotone_constraints_method in ["basic", "intermediate", "advanced"]:
for monotone_constraints_method in ["basic", "intermediate", "advanced"]:
params_constrained_model["monotone_constraints_method"] = monotone_constraints_method
params_constrained_model["monotone_constraints_method"] = monotone_constraints_method
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment