@@ -1273,6 +1273,25 @@ class RandomForestClassifier(ForestClassifier):
1273
1273
1274
1274
.. versionadded:: 0.22
1275
1275
1276
+ monotonic_cst : array-like of int of shape (n_features), default=None
1277
+ Indicates the monotonicity constraint to enforce on each feature.
1278
+ - 1: monotonic increase
1279
+ - 0: no constraint
1280
+ - -1: monotonic decrease
1281
+
1282
+ If monotonic_cst is None, no constraints are applied.
1283
+
1284
+ Monotonicity constraints are not supported for:
1285
+ - multiclass classifications (i.e. when `n_classes > 2`),
1286
+ - multioutput classifications (i.e. when `n_outputs_ > 1`),
1287
+ - classifications trained on data with missing values.
1288
+
1289
+ The constraints hold over the probability of the positive class.
1290
+
1291
+ Read more in the :ref:`User Guide <monotonic_cst_gbdt>`.
1292
+
1293
+ .. versionadded:: 1.4
1294
+
1276
1295
Attributes
1277
1296
----------
1278
1297
estimator_ : :class:`~sklearn.tree.DecisionTreeClassifier`
@@ -1413,6 +1432,7 @@ def __init__(
1413
1432
class_weight = None ,
1414
1433
ccp_alpha = 0.0 ,
1415
1434
max_samples = None ,
1435
+ monotonic_cst = None ,
1416
1436
):
1417
1437
super ().__init__ (
1418
1438
estimator = DecisionTreeClassifier (),
@@ -1428,6 +1448,7 @@ def __init__(
1428
1448
"min_impurity_decrease" ,
1429
1449
"random_state" ,
1430
1450
"ccp_alpha" ,
1451
+ "monotonic_cst" ,
1431
1452
),
1432
1453
bootstrap = bootstrap ,
1433
1454
oob_score = oob_score ,
@@ -1447,6 +1468,7 @@ def __init__(
1447
1468
self .max_features = max_features
1448
1469
self .max_leaf_nodes = max_leaf_nodes
1449
1470
self .min_impurity_decrease = min_impurity_decrease
1471
+ self .monotonic_cst = monotonic_cst
1450
1472
self .ccp_alpha = ccp_alpha
1451
1473
1452
1474
@@ -1627,6 +1649,22 @@ class RandomForestRegressor(ForestRegressor):
1627
1649
1628
1650
.. versionadded:: 0.22
1629
1651
1652
+ monotonic_cst : array-like of int of shape (n_features), default=None
1653
+ Indicates the monotonicity constraint to enforce on each feature.
1654
+ - 1: monotonically increasing
1655
+ - 0: no constraint
1656
+ - -1: monotonically decreasing
1657
+
1658
+ If monotonic_cst is None, no constraints are applied.
1659
+
1660
+ Monotonicity constraints are not supported for:
1661
+ - multioutput regressions (i.e. when `n_outputs_ > 1`),
1662
+ - regressions trained on data with missing values.
1663
+
1664
+ Read more in the :ref:`User Guide <monotonic_cst_gbdt>`.
1665
+
1666
+ .. versionadded:: 1.4
1667
+
1630
1668
Attributes
1631
1669
----------
1632
1670
estimator_ : :class:`~sklearn.tree.DecisionTreeRegressor`
@@ -1754,6 +1792,7 @@ def __init__(
1754
1792
warm_start = False ,
1755
1793
ccp_alpha = 0.0 ,
1756
1794
max_samples = None ,
1795
+ monotonic_cst = None ,
1757
1796
):
1758
1797
super ().__init__ (
1759
1798
estimator = DecisionTreeRegressor (),
@@ -1769,6 +1808,7 @@ def __init__(
1769
1808
"min_impurity_decrease" ,
1770
1809
"random_state" ,
1771
1810
"ccp_alpha" ,
1811
+ "monotonic_cst" ,
1772
1812
),
1773
1813
bootstrap = bootstrap ,
1774
1814
oob_score = oob_score ,
@@ -1788,6 +1828,7 @@ def __init__(
1788
1828
self .max_leaf_nodes = max_leaf_nodes
1789
1829
self .min_impurity_decrease = min_impurity_decrease
1790
1830
self .ccp_alpha = ccp_alpha
1831
+ self .monotonic_cst = monotonic_cst
1791
1832
1792
1833
1793
1834
class ExtraTreesClassifier (ForestClassifier ):
@@ -1975,6 +2016,25 @@ class ExtraTreesClassifier(ForestClassifier):
1975
2016
1976
2017
.. versionadded:: 0.22
1977
2018
2019
+ monotonic_cst : array-like of int of shape (n_features), default=None
2020
+ Indicates the monotonicity constraint to enforce on each feature.
2021
+ - 1: monotonically increasing
2022
+ - 0: no constraint
2023
+ - -1: monotonically decreasing
2024
+
2025
+ If monotonic_cst is None, no constraints are applied.
2026
+
2027
+ Monotonicity constraints are not supported for:
2028
+ - multiclass classifications (i.e. when `n_classes > 2`),
2029
+ - multioutput classifications (i.e. when `n_outputs_ > 1`),
2030
+ - classifications trained on data with missing values.
2031
+
2032
+ The constraints hold over the probability of the positive class.
2033
+
2034
+ Read more in the :ref:`User Guide <monotonic_cst_gbdt>`.
2035
+
2036
+ .. versionadded:: 1.4
2037
+
1978
2038
Attributes
1979
2039
----------
1980
2040
estimator_ : :class:`~sklearn.tree.ExtraTreesClassifier`
@@ -2104,6 +2164,7 @@ def __init__(
2104
2164
class_weight = None ,
2105
2165
ccp_alpha = 0.0 ,
2106
2166
max_samples = None ,
2167
+ monotonic_cst = None ,
2107
2168
):
2108
2169
super ().__init__ (
2109
2170
estimator = ExtraTreeClassifier (),
@@ -2119,6 +2180,7 @@ def __init__(
2119
2180
"min_impurity_decrease" ,
2120
2181
"random_state" ,
2121
2182
"ccp_alpha" ,
2183
+ "monotonic_cst" ,
2122
2184
),
2123
2185
bootstrap = bootstrap ,
2124
2186
oob_score = oob_score ,
@@ -2139,6 +2201,7 @@ def __init__(
2139
2201
self .max_leaf_nodes = max_leaf_nodes
2140
2202
self .min_impurity_decrease = min_impurity_decrease
2141
2203
self .ccp_alpha = ccp_alpha
2204
+ self .monotonic_cst = monotonic_cst
2142
2205
2143
2206
2144
2207
class ExtraTreesRegressor (ForestRegressor ):
@@ -2314,6 +2377,22 @@ class ExtraTreesRegressor(ForestRegressor):
2314
2377
2315
2378
.. versionadded:: 0.22
2316
2379
2380
+ monotonic_cst : array-like of int of shape (n_features), default=None
2381
+ Indicates the monotonicity constraint to enforce on each feature.
2382
+ - 1: monotonically increasing
2383
+ - 0: no constraint
2384
+ - -1: monotonically decreasing
2385
+
2386
+ If monotonic_cst is None, no constraints are applied.
2387
+
2388
+ Monotonicity constraints are not supported for:
2389
+ - multioutput regressions (i.e. when `n_outputs_ > 1`),
2390
+ - regressions trained on data with missing values.
2391
+
2392
+ Read more in the :ref:`User Guide <monotonic_cst_gbdt>`.
2393
+
2394
+ .. versionadded:: 1.4
2395
+
2317
2396
Attributes
2318
2397
----------
2319
2398
estimator_ : :class:`~sklearn.tree.ExtraTreeRegressor`
@@ -2426,6 +2505,7 @@ def __init__(
2426
2505
warm_start = False ,
2427
2506
ccp_alpha = 0.0 ,
2428
2507
max_samples = None ,
2508
+ monotonic_cst = None ,
2429
2509
):
2430
2510
super ().__init__ (
2431
2511
estimator = ExtraTreeRegressor (),
@@ -2441,6 +2521,7 @@ def __init__(
2441
2521
"min_impurity_decrease" ,
2442
2522
"random_state" ,
2443
2523
"ccp_alpha" ,
2524
+ "monotonic_cst" ,
2444
2525
),
2445
2526
bootstrap = bootstrap ,
2446
2527
oob_score = oob_score ,
@@ -2460,6 +2541,7 @@ def __init__(
2460
2541
self .max_leaf_nodes = max_leaf_nodes
2461
2542
self .min_impurity_decrease = min_impurity_decrease
2462
2543
self .ccp_alpha = ccp_alpha
2544
+ self .monotonic_cst = monotonic_cst
2463
2545
2464
2546
2465
2547
class RandomTreesEmbedding (TransformerMixin , BaseForest ):
@@ -2653,7 +2735,7 @@ class RandomTreesEmbedding(TransformerMixin, BaseForest):
2653
2735
** BaseDecisionTree ._parameter_constraints ,
2654
2736
"sparse_output" : ["boolean" ],
2655
2737
}
2656
- for param in ("max_features" , "ccp_alpha" , "splitter" ):
2738
+ for param in ("max_features" , "ccp_alpha" , "splitter" , "monotonic_cst" ):
2657
2739
_parameter_constraints .pop (param )
2658
2740
2659
2741
criterion = "squared_error"
0 commit comments