@@ -1525,9 +1525,31 @@ class RandomForestClassifier(ForestClassifier):
1525
1525
1526
1526
.. versionadded:: 0.22
1527
1527
1528
+ max_bins : int, default=255
1529
+ The maximum number of bins to use for non-missing values.
1530
+
1528
1531
store_leaf_values : bool, default=False
1529
1532
Whether to store the leaf values in the ``get_leaf_node_samples`` function.
1530
1533
1534
+ monotonic_cst : array-like of int of shape (n_features), default=None
1535
+ Indicates the monotonicity constraint to enforce on each feature.
1536
+ - 1: monotonic increase
1537
+ - 0: no constraint
1538
+ - -1: monotonic decrease
1539
+
1540
+ If monotonic_cst is None, no constraints are applied.
1541
+
1542
+ Monotonicity constraints are not supported for:
1543
+ - multiclass classifications (i.e. when `n_classes > 2`),
1544
+ - multioutput classifications (i.e. when `n_outputs_ > 1`),
1545
+ - classifications trained on data with missing values.
1546
+
1547
+ The constraints hold over the probability of the positive class.
1548
+
1549
+ Read more in the :ref:`User Guide <monotonic_cst_gbdt>`.
1550
+
1551
+ .. versionadded:: 1.4
1552
+
1531
1553
Attributes
1532
1554
----------
1533
1555
estimator_ : :class:`~sklearn.tree.DecisionTreeClassifier`
@@ -1670,6 +1692,7 @@ def __init__(
1670
1692
max_samples = None ,
1671
1693
max_bins = None ,
1672
1694
store_leaf_values = False ,
1695
+ monotonic_cst = None ,
1673
1696
):
1674
1697
super ().__init__ (
1675
1698
estimator = DecisionTreeClassifier (),
@@ -1686,6 +1709,7 @@ def __init__(
1686
1709
"random_state" ,
1687
1710
"ccp_alpha" ,
1688
1711
"store_leaf_values" ,
1712
+ "monotonic_cst" ,
1689
1713
),
1690
1714
bootstrap = bootstrap ,
1691
1715
oob_score = oob_score ,
@@ -1707,6 +1731,7 @@ def __init__(
1707
1731
self .max_features = max_features
1708
1732
self .max_leaf_nodes = max_leaf_nodes
1709
1733
self .min_impurity_decrease = min_impurity_decrease
1734
+ self .monotonic_cst = monotonic_cst
1710
1735
self .ccp_alpha = ccp_alpha
1711
1736
1712
1737
@@ -1887,9 +1912,29 @@ class RandomForestRegressor(ForestRegressor):
1887
1912
1888
1913
.. versionadded:: 0.22
1889
1914
1915
+ max_bins : int, default=255
1916
+ The maximum number of bins to use for non-missing values. Used for
1917
+ speeding up training time.
1918
+
1890
1919
store_leaf_values : bool, default=False
1891
1920
Whether to store the leaf values in the ``get_leaf_node_samples`` function.
1892
1921
1922
+ monotonic_cst : array-like of int of shape (n_features), default=None
1923
+ Indicates the monotonicity constraint to enforce on each feature.
1924
+ - 1: monotonically increasing
1925
+ - 0: no constraint
1926
+ - -1: monotonically decreasing
1927
+
1928
+ If monotonic_cst is None, no constraints are applied.
1929
+
1930
+ Monotonicity constraints are not supported for:
1931
+ - multioutput regressions (i.e. when `n_outputs_ > 1`),
1932
+ - regressions trained on data with missing values.
1933
+
1934
+ Read more in the :ref:`User Guide <monotonic_cst_gbdt>`.
1935
+
1936
+ .. versionadded:: 1.4
1937
+
1893
1938
Attributes
1894
1939
----------
1895
1940
estimator_ : :class:`~sklearn.tree.DecisionTreeRegressor`
@@ -2019,6 +2064,7 @@ def __init__(
2019
2064
max_samples = None ,
2020
2065
max_bins = None ,
2021
2066
store_leaf_values = False ,
2067
+ monotonic_cst = None ,
2022
2068
):
2023
2069
super ().__init__ (
2024
2070
estimator = DecisionTreeRegressor (),
@@ -2035,6 +2081,7 @@ def __init__(
2035
2081
"random_state" ,
2036
2082
"ccp_alpha" ,
2037
2083
"store_leaf_values" ,
2084
+ "monotonic_cst" ,
2038
2085
),
2039
2086
bootstrap = bootstrap ,
2040
2087
oob_score = oob_score ,
@@ -2056,6 +2103,7 @@ def __init__(
2056
2103
self .max_leaf_nodes = max_leaf_nodes
2057
2104
self .min_impurity_decrease = min_impurity_decrease
2058
2105
self .ccp_alpha = ccp_alpha
2106
+ self .monotonic_cst = monotonic_cst
2059
2107
2060
2108
2061
2109
class ExtraTreesClassifier (ForestClassifier ):
@@ -2242,10 +2290,32 @@ class ExtraTreesClassifier(ForestClassifier):
2242
2290
`max_samples` should be in the interval `(0.0, 1.0]`.
2243
2291
2244
2292
.. versionadded:: 0.22
2293
+
2294
+ max_bins : int, default=255
2295
+ The maximum number of bins to use for non-missing values.
2245
2296
2246
2297
store_leaf_values : bool, default=False
2247
2298
Whether to store the leaf values in the ``get_leaf_node_samples`` function.
2248
2299
2300
+ monotonic_cst : array-like of int of shape (n_features), default=None
2301
+ Indicates the monotonicity constraint to enforce on each feature.
2302
+ - 1: monotonically increasing
2303
+ - 0: no constraint
2304
+ - -1: monotonically decreasing
2305
+
2306
+ If monotonic_cst is None, no constraints are applied.
2307
+
2308
+ Monotonicity constraints are not supported for:
2309
+ - multiclass classifications (i.e. when `n_classes > 2`),
2310
+ - multioutput classifications (i.e. when `n_outputs_ > 1`),
2311
+ - classifications trained on data with missing values.
2312
+
2313
+ The constraints hold over the probability of the positive class.
2314
+
2315
+ Read more in the :ref:`User Guide <monotonic_cst_gbdt>`.
2316
+
2317
+ .. versionadded:: 1.4
2318
+
2249
2319
Attributes
2250
2320
----------
2251
2321
estimator_ : :class:`~sklearn.tree.ExtraTreesClassifier`
@@ -2377,6 +2447,7 @@ def __init__(
2377
2447
max_samples = None ,
2378
2448
max_bins = None ,
2379
2449
store_leaf_values = False ,
2450
+ monotonic_cst = None ,
2380
2451
):
2381
2452
super ().__init__ (
2382
2453
estimator = ExtraTreeClassifier (),
@@ -2393,6 +2464,7 @@ def __init__(
2393
2464
"random_state" ,
2394
2465
"ccp_alpha" ,
2395
2466
"store_leaf_values" ,
2467
+ "monotonic_cst" ,
2396
2468
),
2397
2469
bootstrap = bootstrap ,
2398
2470
oob_score = oob_score ,
@@ -2415,6 +2487,7 @@ def __init__(
2415
2487
self .max_leaf_nodes = max_leaf_nodes
2416
2488
self .min_impurity_decrease = min_impurity_decrease
2417
2489
self .ccp_alpha = ccp_alpha
2490
+ self .monotonic_cst = monotonic_cst
2418
2491
2419
2492
2420
2493
class ExtraTreesRegressor (ForestRegressor ):
@@ -2590,9 +2663,28 @@ class ExtraTreesRegressor(ForestRegressor):
2590
2663
2591
2664
.. versionadded:: 0.22
2592
2665
2666
+ max_bins : int, default=255
2667
+ The maximum number of bins to use for non-missing values.
2668
+
2593
2669
store_leaf_values : bool, default=False
2594
2670
Whether to store the leaf values in the ``get_leaf_node_samples`` function.
2595
2671
2672
+ monotonic_cst : array-like of int of shape (n_features), default=None
2673
+ Indicates the monotonicity constraint to enforce on each feature.
2674
+ - 1: monotonically increasing
2675
+ - 0: no constraint
2676
+ - -1: monotonically decreasing
2677
+
2678
+ If monotonic_cst is None, no constraints are applied.
2679
+
2680
+ Monotonicity constraints are not supported for:
2681
+ - multioutput regressions (i.e. when `n_outputs_ > 1`),
2682
+ - regressions trained on data with missing values.
2683
+
2684
+ Read more in the :ref:`User Guide <monotonic_cst_gbdt>`.
2685
+
2686
+ .. versionadded:: 1.4
2687
+
2596
2688
Attributes
2597
2689
----------
2598
2690
estimator_ : :class:`~sklearn.tree.ExtraTreeRegressor`
@@ -2707,6 +2799,7 @@ def __init__(
2707
2799
max_samples = None ,
2708
2800
max_bins = None ,
2709
2801
store_leaf_values = False ,
2802
+ monotonic_cst = None ,
2710
2803
):
2711
2804
super ().__init__ (
2712
2805
estimator = ExtraTreeRegressor (),
@@ -2723,6 +2816,7 @@ def __init__(
2723
2816
"random_state" ,
2724
2817
"ccp_alpha" ,
2725
2818
"store_leaf_values" ,
2819
+ "monotonic_cst" ,
2726
2820
),
2727
2821
bootstrap = bootstrap ,
2728
2822
oob_score = oob_score ,
@@ -2744,6 +2838,7 @@ def __init__(
2744
2838
self .max_leaf_nodes = max_leaf_nodes
2745
2839
self .min_impurity_decrease = min_impurity_decrease
2746
2840
self .ccp_alpha = ccp_alpha
2841
+ self .monotonic_cst = monotonic_cst
2747
2842
2748
2843
2749
2844
class RandomTreesEmbedding (TransformerMixin , BaseForest ):
@@ -2937,7 +3032,7 @@ class RandomTreesEmbedding(TransformerMixin, BaseForest):
2937
3032
** BaseDecisionTree ._parameter_constraints ,
2938
3033
"sparse_output" : ["boolean" ],
2939
3034
}
2940
- for param in ("max_features" , "ccp_alpha" , "splitter" ):
3035
+ for param in ("max_features" , "ccp_alpha" , "splitter" , "monotonic_cst" ):
2941
3036
_parameter_constraints .pop (param )
2942
3037
2943
3038
criterion = "squared_error"
0 commit comments