Skip to content

ENH Monotonic Contraints for Tree-based models #13649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 203 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
203 commits
Select commit Hold shift + click to select a range
1b0a960
Monotonic features in tree-based models
pat-oreilly Aug 26, 2016
953651f
refactoring monotonic check into a function
pat-oreilly Aug 28, 2016
63c3f9c
tidy up monotonic check function
pat-oreilly Sep 2, 2016
6407e99
fix typo 'decreasin'
pat-oreilly Sep 7, 2016
92f7537
Merge branch 'master' into monotonic-trees
samronsin Apr 14, 2019
119d5a3
Clean up dirty merge
samronsin Apr 14, 2019
c331e82
PEP8
samronsin Apr 15, 2019
ab6d185
PEP8
samronsin Apr 15, 2019
ce9377f
PEP8
samronsin Apr 15, 2019
fe21579
Update docstrings for increasing/decreasing parameters
samronsin Apr 25, 2019
642dcb0
Merge branch 'master' into monotonic-trees
samronsin Apr 25, 2019
544cced
Cleanup
samronsin Apr 25, 2019
20c7929
Cleanup
samronsin Apr 25, 2019
8cd9954
Merge branch 'master' into monotonic-trees
samronsin Jun 14, 2019
49747c6
Add basic monotonicity tests
samronsin Jun 17, 2019
37b536b
PEP8
samronsin Jun 17, 2019
ef2fb1c
PEP8
samronsin Jun 17, 2019
072ef99
Simplify split_passes_monotonic_check function
samronsin Jun 20, 2019
605e1c8
Fix split_passes_monotonic_check function
samronsin Jun 20, 2019
018d6c2
Fix tests (still something broken though)
samronsin Jun 20, 2019
347e2c6
Merge branch 'master' into monotonic-trees
samronsin Jan 29, 2020
b217ec8
Fix PEP8 and missing import in tests
samronsin Jan 29, 2020
be8b38a
Fix faulty Splitter call in _classes.py
samronsin Jan 29, 2020
5aacb40
Remove merge bruises
samronsin Jan 29, 2020
ef05889
Remove deprecated asserts
samronsin Jan 29, 2020
8ac9945
changing decreasing/increasing to monotonic_cst
dsleo Jan 29, 2020
8a687c1
Fix segfault caused by sending None instead of np.array to Splitter init
samronsin Jan 29, 2020
900ed04
Fix tests
samronsin Jan 29, 2020
15fe7b5
fix linting
dsleo Jan 30, 2020
803efe0
Preliminary pass at adding upper and lower bounds on splits
samronsin Jan 30, 2020
23da3e7
Work towards adding upper and lower bounds on splits and nodes
samronsin Jan 31, 2020
f73c820
YOLO
samronsin Jan 31, 2020
d43a4a9
Do the easier TODOs
samronsin Feb 3, 2020
822bd5b
Roll back adding bound information to nodes
samronsin Feb 10, 2020
e485416
Add bound information to intermediate tree-building structures
samronsin Feb 10, 2020
b735ff8
Merge branch 'master' of https://github.com/scikit-learn/scikit-learn…
samronsin Apr 27, 2020
32e4c70
Add monotonicity tests for tree with single feature
samronsin Apr 27, 2020
8c39842
Add test for best first tree builder
samronsin Apr 28, 2020
89fd890
Fix monotonicity checks related to bounds
samronsin Apr 28, 2020
678b1f8
Fix depth-first tree building with decreasing constraint
samronsin Apr 28, 2020
0ce8b3a
Clean up
samronsin Apr 28, 2020
2fac624
Add tests for random splitter
samronsin Apr 28, 2020
cafb309
Clean up Stack
samronsin Apr 28, 2020
4601690
Clean up PriorityHeap
samronsin Apr 28, 2020
3ee90f6
Clean up PriorityHeap
samronsin Apr 28, 2020
1bfdc4c
Fix wrong test for leaves and seed trees
samronsin Apr 29, 2020
3366a30
Make tests consistents with implemented bounding strategy
samronsin Apr 29, 2020
4634dea
Fix monotonicity checks
samronsin Apr 29, 2020
a7b4133
Clean up depth-first tree building
samronsin Apr 29, 2020
c2cecf5
Fix and clean up best-first tree building
samronsin Apr 29, 2020
4764cf4
Flake8
samronsin Apr 29, 2020
dcc9f18
Formatting
samronsin Apr 30, 2020
84b912b
Raise ValueError on multiclass
samronsin Apr 30, 2020
60a4b8c
Linting
samronsin Apr 30, 2020
3ccb540
Fix previous merge
samronsin Apr 30, 2020
5f75c1c
Remove useless check when splitting on unconstrainted feature
samronsin May 4, 2020
5feda05
Merge branch 'master' into monotonic-trees
samronsin Jun 2, 2020
05d023c
Group monotonic tree tests into dedicated file
samronsin Jun 2, 2020
3fd364f
Fix linting
samronsin Jun 2, 2020
711c2ee
Merge branch 'master' into monotonic-trees
samronsin Jun 24, 2020
e94c9a2
Merge branch 'master' into monotonic-trees
samronsin Feb 5, 2021
de6341f
Make test_montonic_constraints harder to pass
samronsin Feb 10, 2021
3a78b94
Fix tree regressions by enforcing bounds for all splits
samronsin Feb 12, 2021
5090853
Make test_montonic_constraints harder to pass
samronsin Feb 16, 2021
70f0276
Fix middle value bound for classifications
samronsin Feb 16, 2021
930ed41
Clean up, document and comment
samronsin Feb 16, 2021
b4d1757
Clean up
samronsin Feb 16, 2021
b73984d
Fix ExtraTreeRegressor Docstring
samronsin Feb 16, 2021
173db43
Clean up
samronsin Feb 16, 2021
c4e119d
Clean up tests
samronsin Feb 18, 2021
fc50799
Add test for multi-features trees
samronsin Feb 18, 2021
6312564
Merge branch 'main' into monotonic-trees
ogrisel Jun 3, 2021
847cc4f
Apply suggestions from code review
samronsin Jun 18, 2021
08f8247
Apply more suggestions from code review
samronsin Jun 18, 2021
5a92399
Test error message for multiclass
samronsin Jun 21, 2021
08dadd1
Merge commit '0e7761cdc4f244adb4803f1a97f0a9fe4b365a99' into monotoni…
samronsin Jun 21, 2021
c2e6e4e
MAINT Adds target_version to black config (#20293)
thomasjpfan Jun 17, 2021
b88a637
Add formatting changes from black
samronsin Jun 21, 2021
46c9087
Merge remote-tracking branch 'upstream/main' into monotonic-trees
samronsin Jun 21, 2021
66032e5
Make the monotonicity constraints hold on the positive class for bina…
samronsin Jun 21, 2021
e6264d3
Adapt gradient boosting to disable modifying leaves (line search) and…
samronsin Jun 24, 2021
d196ace
Add tests for gradient boosting and removing tests for forests
samronsin Jun 24, 2021
250996a
Format
samronsin Jun 24, 2021
df31697
Add whats_new entry
samronsin Jun 24, 2021
e6937d9
Fix 1/-1 mixup in the docstrings relative to positive/negative constr…
samronsin Nov 30, 2021
56b361d
Apply suggestions from code review
samronsin Nov 30, 2021
0d1fa94
Merge remote-tracking branch 'upstream/main' into monotonic-trees
samronsin Nov 30, 2021
ba95efa
Move blurbs to latest whats_new
samronsin Nov 30, 2021
b764a89
Remove named argument for cdef function and use deref instead of [0] …
samronsin Dec 1, 2021
c721fa6
Update wording in docstring for perform_line_search argument
samronsin Dec 1, 2021
f4ebabe
Split test_montonic_constraints into two tests for classifications/re…
samronsin Dec 1, 2021
c0fa6f8
Add name of arguments to stack.push calls as comments
samronsin Dec 1, 2021
70de129
Add test for incorrect input
samronsin Dec 1, 2021
20590d5
Add blank line
samronsin Dec 1, 2021
573aa79
Format
samronsin Dec 2, 2021
03ee5f4
Factor the logic computing the middle value
jjerphan Dec 3, 2021
779efcb
Apply Julien's suggestions in tests
samronsin May 12, 2022
1426e1d
Clean up check of monotonic_cst values
samronsin May 12, 2022
1db26e0
Use local variables for attributes and initialize on definition
samronsin May 12, 2022
e87e40a
Add comments in BestFirstTreeBuilder
samronsin May 12, 2022
f03f089
Update methods signature format for readability
samronsin May 12, 2022
cc446f6
Update methods signature format for readability
samronsin May 12, 2022
24366d7
Merge branch 'main' into monotonic-trees
samronsin May 12, 2022
c8ec3c4
Format
samronsin May 12, 2022
0a02f62
Fix gil stuff and stuff
samronsin May 12, 2022
771bc3f
Merge branch 'main' into monotonic-trees
samronsin May 16, 2022
dea6bda
Fix -1 0 1 monotonic_cst check
samronsin May 18, 2022
1c943a3
Move check_monotonicity from Splitter to Criterion
samronsin May 18, 2022
b0a0317
Fix premature call to check_monotonicity in RandomSparseSplitter
samronsin May 18, 2022
b784e04
Remove unnecessary GIL-taking
samronsin May 18, 2022
f68a27b
Fix formatting
samronsin May 18, 2022
daf54cd
Merge branch 'main' into monotonic-trees
ogrisel May 19, 2022
38ce5a7
Merge branch 'main' into monotonic-trees
jjerphan Jul 20, 2022
8b795e7
Add monotonic_cst to parameter contraints for decision tree models
samronsin Jul 20, 2022
279ab6a
Misc formatting
samronsin Jul 20, 2022
79d345b
Fix early casting to int beaking test when input is not int
samronsin Jul 20, 2022
0367f26
Replace paramaterized seed by global_random_seed fixture
samronsin Jul 20, 2022
c6e955d
Comment inline the bounds propagation
samronsin Jul 20, 2022
bde6754
Fix format
samronsin Jul 20, 2022
2d8b025
Fix format
samronsin Jul 20, 2022
efb6424
Add example of incorrect tree if bounds and checks are not propagated…
samronsin Jul 20, 2022
896ef6f
Update whats_new entry
samronsin Jul 22, 2022
cc4be1a
Reduce dataset size in test
samronsin Jul 22, 2022
bf78a7f
Merge branch 'main' into monotonic-trees
samronsin Sep 6, 2022
23d3a2b
MAINT Adapt logic to use the latest NumPy API
jjerphan Sep 7, 2022
69a0dd8
Clean up cimports in _splitter.pyx
samronsin Sep 7, 2022
6eab6e0
Merge branch 'main' into monotonic-trees
samronsin Sep 7, 2022
baa1cf6
Revert hist_gradient_boosting docstring correction to save for a dedi…
samronsin Sep 7, 2022
26a69c0
Address compilation warnings on uninitialised variables
samronsin Sep 7, 2022
66a18e0
Use keyword arguments in _add_split_node calls
samronsin Sep 7, 2022
bbf5fb2
Qualify Splitter.monotonic_cst as const and switch to MemoryView
samronsin Sep 7, 2022
96923b6
Revert "Use keyword arguments in _add_split_node calls"
samronsin Sep 7, 2022
e06806a
Factorize common regression and classification logic of constraints c…
samronsin Sep 7, 2022
7bfb603
Revert "Qualify Splitter.monotonic_cst as const and switch to MemoryV…
samronsin Sep 7, 2022
8065ab7
Qualify Splitter.monotonic_cst as const
samronsin Sep 7, 2022
1083303
Merge branch 'main' into monotonic-trees
samronsin Sep 7, 2022
c54eab9
Use MemoryViews for monotonic_cst instead of pointers
samronsin Sep 8, 2022
eb4ee0f
Use keyword arguments in _add_split_node calls
samronsin Sep 8, 2022
1cbc5d8
CI Retrigger CI due to assert reproducibility of the faulty run
jjerphan Sep 9, 2022
438d224
Remove unused get_sum_total
jjerphan Sep 14, 2022
301fb4e
Replace positive/negative wording by increasing/decreasing and use bu…
samronsin Sep 14, 2022
a491f59
Fix docstrings
samronsin Sep 14, 2022
1c7ac01
Fix docstrings
samronsin Sep 14, 2022
3e9b3a8
Merge branch 'main' into monotonic-trees
jjerphan Sep 27, 2022
d65c437
Remove monotonic_cst for RandomTreesEmbedding
ogrisel Oct 27, 2022
56966a6
Use np.int8 by default
ogrisel Oct 27, 2022
e00ab65
Apply suggestions from code review
ogrisel Oct 27, 2022
e047f52
Apply suggestions from code review
ogrisel Oct 27, 2022
3ba9c10
Merge branch 'main' into monotonic-trees
ogrisel Oct 27, 2022
c70c1b6
Missing .. versionadded:: 1.2 & more consistent docstrings
ogrisel Oct 27, 2022
e41435f
Fix linter
ogrisel Oct 27, 2022
3a46ff6
Monotonic increase
ogrisel Oct 27, 2022
7a39219
Encode monotonicity constraints with cnp.int8
jjerphan Oct 28, 2022
dd5df85
Fix docstring format of ExtraTreesClassifier (double blank line)
ogrisel Oct 28, 2022
7c2536f
Merge branch 'main' into HEAD
jjerphan Oct 28, 2022
2b596ec
Remove monotonic_cst support for GradientBoosting for now
jjerphan Oct 28, 2022
b9c7a90
DOC Clarify wording for constraints
jjerphan Oct 28, 2022
94d993c
TST Parametrize tests and simplify parameters' lists
jjerphan Oct 28, 2022
41e443e
MAINT Format ala black
jjerphan Oct 28, 2022
bf0a106
Remove irrelevant changes
jjerphan Oct 28, 2022
ec9cb4a
fixup! DOC Clarify wording for constraints
jjerphan Oct 28, 2022
0d58fe5
Use global_random_seed in data generation for tests
ogrisel Oct 28, 2022
23d4497
English grammar
ogrisel Oct 28, 2022
bfe94af
Optim: protect check_monotonicity under monotonic_constraint != 0
ogrisel Oct 28, 2022
9e1f8b1
Revert "Optim: protect check_monotonicity under monotonic_constraint …
ogrisel Oct 28, 2022
3fdae14
Test clean-up
ogrisel Oct 28, 2022
7e33b05
PERF Use monotonic_cst only is it is provided
jjerphan Oct 28, 2022
1cae8ee
Improve comments in _get_middle_value
ogrisel Oct 28, 2022
3558bfd
Only compute bounds' middle_value when needed
jjerphan Nov 2, 2022
35ae0a3
More intuitive assert_nd_reg_tree_children_monotonic_bounded
ogrisel Nov 4, 2022
5926abe
WIP try to test assert_nd_reg_tree_children_monotonic_bounded
ogrisel Nov 4, 2022
a650224
Apply suggestions from code review
ogrisel Nov 4, 2022
68ccb72
Merge branch 'main' into monotonic-trees
samronsin Jun 14, 2023
6809be7
Clean up
samronsin Jun 14, 2023
104600e
Merge branch 'main' into monotonic-trees
samronsin Jun 14, 2023
27895f5
Implement middle value as unweighted average of right and left childr…
samronsin Jun 15, 2023
a73c765
Merge branch 'main' into monotonic-trees
samronsin Jun 15, 2023
c6e27d6
Fix broken test caused by Splitter init change
samronsin Jun 15, 2023
187a534
Clean up
samronsin Jun 16, 2023
b4142c8
Make cython-lint happy
jjerphan Jun 19, 2023
55a0544
Improve and test assert_1d_reg_tree_children_monotonic_bounded
samronsin Jun 19, 2023
e92a10a
Remove excessive assertions from test_assert_nd_reg_tree_children_mon…
samronsin Jun 19, 2023
ca7f031
Add tree ensembles to estimator tests
samronsin Jun 19, 2023
e49a58b
Clean up tests
samronsin Jun 19, 2023
e89fa57
Optimize Criterion modifications
samronsin Jun 19, 2023
80594a2
Black stuff + check that float value is not cast too early to int8
samronsin Jun 19, 2023
7f9dc71
Add test with opposite monotonicity data and constraints
samronsin Jun 19, 2023
4e3edac
Implement value clipping
samronsin Jun 21, 2023
4e1d784
Remove redundant tests: splitter kwarg is equivalent to choice of {De…
samronsin Jun 21, 2023
cec0207
Merge branch 'main' into monotonic-trees
samronsin Jun 21, 2023
4e509fe
Extend test coverage to random splitters
samronsin Jun 21, 2023
c0483da
Add support for absolute error regression criterion
samronsin Jun 21, 2023
87bae8b
Merge branch 'main' into monotonic-trees
samronsin Jun 22, 2023
16a8863
Mark missing values as unsupported
samronsin Jun 22, 2023
c08c4bf
Update docstrings to specify training data with missing values is not…
samronsin Jun 22, 2023
e77c505
DOC Add changelog entries
jjerphan Jun 24, 2023
75242d9
Merge branch 'main' into monotonic-trees
jjerphan Jun 24, 2023
9b3bc22
Add comment regarding monotonic_cst sign flipping for classification …
samronsin Jun 30, 2023
816778d
Use np.isin to validate monotonic_cst
samronsin Jun 30, 2023
88ae965
Update whats_new
samronsin Jun 30, 2023
31d5edb
Fix lign too long
samronsin Jun 30, 2023
e763020
Merge branch 'main' into monotonic-trees
samronsin Jun 30, 2023
57c78a5
Add pointers to user guide
samronsin Jun 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions doc/whats_new/v1.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ TODO: update at the time of the release.
passed to the ``fit`` method of the the estimator. :pr:`26506` by `Adrin
Jalali`_.


:mod:`sklearn.ensemble`
.......................

- |Feature| :class:`ensemble.RandomForestClassifier`,
:class:`ensemble.RandomForestRegressor`, :class:`ensemble.ExtraTreesClassifier`
and :class:`ensemble.ExtraTreesRegressor` now support monotonic constraints,
useful when features are supposed to have a positive/negative effect on the target.
Missing values in the train data and multi-output targets are not supported.
:pr:`13649` by :user:`Samuel Ronsin <samronsin>`,
initiated by :user:`Patrick O'Reilly <pat-oreilly>`.


:mod:`sklearn.tree`
...................

- |Feature| :class:`tree.DecisionTreeClassifier`, :class:`tree.DecisionTreeRegressor`,
:class:`tree.ExtraTreeClassifier` and :class:`tree.ExtraTreeRegressor` now support
monotonic constraints, useful when features are supposed to have a positive/negative
effect on the target. Missing values in the train data and multi-output targets are
not supported.
:pr:`13649` by :user:`Samuel Ronsin <samronsin>`, initiated by
:user:`Patrick O'Reilly <pat-oreilly>`.


:mod:`sklearn.decomposition`
............................

Expand Down
84 changes: 83 additions & 1 deletion sklearn/ensemble/_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,25 @@ class RandomForestClassifier(ForestClassifier):

.. versionadded:: 0.22

monotonic_cst : array-like of int of shape (n_features), default=None
Indicates the monotonicity constraint to enforce on each feature.
- 1: monotonic increase
- 0: no constraint
- -1: monotonic decrease

If monotonic_cst is None, no constraints are applied.

Monotonicity constraints are not supported for:
- multiclass classifications (i.e. when `n_classes > 2`),
- multioutput classifications (i.e. when `n_outputs_ > 1`),
- classifications trained on data with missing values.

The constraints hold over the probability of the positive class.

Read more in the :ref:`User Guide <monotonic_cst_gbdt>`.

.. versionadded:: 1.4

Attributes
----------
estimator_ : :class:`~sklearn.tree.DecisionTreeClassifier`
Expand Down Expand Up @@ -1413,6 +1432,7 @@ def __init__(
class_weight=None,
ccp_alpha=0.0,
max_samples=None,
monotonic_cst=None,
):
super().__init__(
estimator=DecisionTreeClassifier(),
Expand All @@ -1428,6 +1448,7 @@ def __init__(
"min_impurity_decrease",
"random_state",
"ccp_alpha",
"monotonic_cst",
),
bootstrap=bootstrap,
oob_score=oob_score,
Expand All @@ -1447,6 +1468,7 @@ def __init__(
self.max_features = max_features
self.max_leaf_nodes = max_leaf_nodes
self.min_impurity_decrease = min_impurity_decrease
self.monotonic_cst = monotonic_cst
self.ccp_alpha = ccp_alpha


Expand Down Expand Up @@ -1627,6 +1649,22 @@ class RandomForestRegressor(ForestRegressor):

.. versionadded:: 0.22

monotonic_cst : array-like of int of shape (n_features), default=None
Indicates the monotonicity constraint to enforce on each feature.
- 1: monotonically increasing
- 0: no constraint
- -1: monotonically decreasing

If monotonic_cst is None, no constraints are applied.

Monotonicity constraints are not supported for:
- multioutput regressions (i.e. when `n_outputs_ > 1`),
- regressions trained on data with missing values.

Read more in the :ref:`User Guide <monotonic_cst_gbdt>`.

.. versionadded:: 1.4

Attributes
----------
estimator_ : :class:`~sklearn.tree.DecisionTreeRegressor`
Expand Down Expand Up @@ -1754,6 +1792,7 @@ def __init__(
warm_start=False,
ccp_alpha=0.0,
max_samples=None,
monotonic_cst=None,
):
super().__init__(
estimator=DecisionTreeRegressor(),
Expand All @@ -1769,6 +1808,7 @@ def __init__(
"min_impurity_decrease",
"random_state",
"ccp_alpha",
"monotonic_cst",
),
bootstrap=bootstrap,
oob_score=oob_score,
Expand All @@ -1788,6 +1828,7 @@ def __init__(
self.max_leaf_nodes = max_leaf_nodes
self.min_impurity_decrease = min_impurity_decrease
self.ccp_alpha = ccp_alpha
self.monotonic_cst = monotonic_cst


class ExtraTreesClassifier(ForestClassifier):
Expand Down Expand Up @@ -1975,6 +2016,25 @@ class ExtraTreesClassifier(ForestClassifier):

.. versionadded:: 0.22

monotonic_cst : array-like of int of shape (n_features), default=None
Indicates the monotonicity constraint to enforce on each feature.
- 1: monotonically increasing
- 0: no constraint
- -1: monotonically decreasing

If monotonic_cst is None, no constraints are applied.

Monotonicity constraints are not supported for:
- multiclass classifications (i.e. when `n_classes > 2`),
- multioutput classifications (i.e. when `n_outputs_ > 1`),
- classifications trained on data with missing values.

The constraints hold over the probability of the positive class.

Read more in the :ref:`User Guide <monotonic_cst_gbdt>`.

.. versionadded:: 1.4

Attributes
----------
estimator_ : :class:`~sklearn.tree.ExtraTreesClassifier`
Expand Down Expand Up @@ -2104,6 +2164,7 @@ def __init__(
class_weight=None,
ccp_alpha=0.0,
max_samples=None,
monotonic_cst=None,
):
super().__init__(
estimator=ExtraTreeClassifier(),
Expand All @@ -2119,6 +2180,7 @@ def __init__(
"min_impurity_decrease",
"random_state",
"ccp_alpha",
"monotonic_cst",
),
bootstrap=bootstrap,
oob_score=oob_score,
Expand All @@ -2139,6 +2201,7 @@ def __init__(
self.max_leaf_nodes = max_leaf_nodes
self.min_impurity_decrease = min_impurity_decrease
self.ccp_alpha = ccp_alpha
self.monotonic_cst = monotonic_cst


class ExtraTreesRegressor(ForestRegressor):
Expand Down Expand Up @@ -2314,6 +2377,22 @@ class ExtraTreesRegressor(ForestRegressor):

.. versionadded:: 0.22

monotonic_cst : array-like of int of shape (n_features), default=None
Indicates the monotonicity constraint to enforce on each feature.
- 1: monotonically increasing
- 0: no constraint
- -1: monotonically decreasing

If monotonic_cst is None, no constraints are applied.

Monotonicity constraints are not supported for:
- multioutput regressions (i.e. when `n_outputs_ > 1`),
- regressions trained on data with missing values.

Read more in the :ref:`User Guide <monotonic_cst_gbdt>`.

.. versionadded:: 1.4

Attributes
----------
estimator_ : :class:`~sklearn.tree.ExtraTreeRegressor`
Expand Down Expand Up @@ -2426,6 +2505,7 @@ def __init__(
warm_start=False,
ccp_alpha=0.0,
max_samples=None,
monotonic_cst=None,
):
super().__init__(
estimator=ExtraTreeRegressor(),
Expand All @@ -2441,6 +2521,7 @@ def __init__(
"min_impurity_decrease",
"random_state",
"ccp_alpha",
"monotonic_cst",
),
bootstrap=bootstrap,
oob_score=oob_score,
Expand All @@ -2460,6 +2541,7 @@ def __init__(
self.max_leaf_nodes = max_leaf_nodes
self.min_impurity_decrease = min_impurity_decrease
self.ccp_alpha = ccp_alpha
self.monotonic_cst = monotonic_cst


class RandomTreesEmbedding(TransformerMixin, BaseForest):
Expand Down Expand Up @@ -2653,7 +2735,7 @@ class RandomTreesEmbedding(TransformerMixin, BaseForest):
**BaseDecisionTree._parameter_constraints,
"sparse_output": ["boolean"],
}
for param in ("max_features", "ccp_alpha", "splitter"):
for param in ("max_features", "ccp_alpha", "splitter", "monotonic_cst"):
_parameter_constraints.pop(param)

criterion = "squared_error"
Expand Down
1 change: 1 addition & 0 deletions sklearn/ensemble/_gb.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class BaseGradientBoosting(BaseEnsemble, metaclass=ABCMeta):
"tol": [Interval(Real, 0.0, None, closed="left")],
}
_parameter_constraints.pop("splitter")
_parameter_constraints.pop("monotonic_cst")

@abstractmethod
def __init__(
Expand Down
Loading