1010from sklearn .tree import DecisionTreeClassifier
1111from sklearn .utils import _safe_indexing
1212from sklearn .utils .fixes import parse_version
13+ from sklearn .utils .metaestimators import available_if
1314from sklearn .utils .validation import has_fit_parameter
1415
1516from ..base import _ParamsValidationMixin
1819from ..under_sampling .base import BaseUnderSampler
1920from ..utils import Substitution , check_target_type
2021from ..utils ._docstring import _random_state_docstring
21- from ..utils ._param_validation import Interval , StrOptions
22- from ..utils .fixes import _fit_context
22+ from ..utils ._param_validation import Hidden , Interval , StrOptions
23+ from ..utils .fixes import _fit_context , check_version_package
2324from ._common import _adaboost_classifier_parameter_constraints
2425
2526sklearn_version = parse_version (sklearn .__version__ )
@@ -58,16 +59,18 @@ class RUSBoostClassifier(_ParamsValidationMixin, AdaBoostClassifier):
5859 ``learning_rate``. There is a trade-off between ``learning_rate`` and
5960 ``n_estimators``.
6061
61- algorithm : {{'SAMME', 'SAMME.R'}}, default='SAMME.R '
62+ algorithm : {{'SAMME', 'SAMME.R'}}, default='deprecated '
6263 If 'SAMME.R' then use the SAMME.R real boosting algorithm.
6364 ``base_estimator`` must support calculation of class probabilities.
6465 If 'SAMME' then use the SAMME discrete boosting algorithm.
6566 The SAMME.R algorithm typically converges faster than SAMME,
6667 achieving a lower test error with fewer boosting iterations.
6768
6869 .. deprecated:: 0.12
69- `"SAMME.R"` is deprecated and will be removed in version 0.14.
70- '"SAMME"' will become the default.
70+ `algorithm` is deprecated in 0.12 and will be removed 0.14.
71+ Depending on the `scikit-learn` version, the "SAMME.R" algorithm might not
72+ be available. Refer to the documentation of
73+ :class:`~sklearn.ensemble.AdaBoostClassifier` for more information.
7174
7275 {sampling_strategy}
7376
@@ -109,7 +112,7 @@ class RUSBoostClassifier(_ParamsValidationMixin, AdaBoostClassifier):
109112 ensemble.
110113
111114 feature_importances_ : ndarray of shape (n_features,)
112- The feature importances if supported by the ``base_estimator ``.
115+ The feature importances if supported by the ``estimator ``.
113116
114117 n_features_in_ : int
115118 Number of features in the input dataset.
@@ -167,6 +170,10 @@ class RUSBoostClassifier(_ParamsValidationMixin, AdaBoostClassifier):
167170
168171 _parameter_constraints .update (
169172 {
173+ "algorithm" : [
174+ StrOptions ({"SAMME" , "SAMME.R" }),
175+ Hidden (StrOptions ({"deprecated" })),
176+ ],
170177 "sampling_strategy" : [
171178 Interval (numbers .Real , 0 , 1 , closed = "right" ),
172179 StrOptions ({"auto" , "majority" , "not minority" , "not majority" , "all" }),
@@ -186,17 +193,17 @@ def __init__(
186193 * ,
187194 n_estimators = 50 ,
188195 learning_rate = 1.0 ,
189- algorithm = "SAMME.R " ,
196+ algorithm = "deprecated " ,
190197 sampling_strategy = "auto" ,
191198 replacement = False ,
192199 random_state = None ,
193200 ):
194201 super ().__init__ (
195202 n_estimators = n_estimators ,
196203 learning_rate = learning_rate ,
197- algorithm = algorithm ,
198204 random_state = random_state ,
199205 )
206+ self .algorithm = algorithm
200207 self .estimator = estimator
201208 self .sampling_strategy = sampling_strategy
202209 self .replacement = replacement
@@ -394,3 +401,7 @@ def _boost_discrete(self, iboost, X, y, sample_weight, random_state):
394401 sample_weight *= np .exp (estimator_weight * incorrect * (sample_weight > 0 ))
395402
396403 return sample_weight , estimator_weight , estimator_error
404+
405+ @available_if (check_version_package ("sklearn" , ">=" , "1.6" ))
406+ def _boost (self , iboost , X , y , sample_weight , random_state ):
407+ return self ._boost_discrete (iboost , X , y , sample_weight , random_state )
0 commit comments