8000 AdaBoost: allow base_estimator=None by markotoplak · Pull Request #26242 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

AdaBoost: allow base_estimator=None #26242

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
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions doc/whats_new/v1.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ Changelog
pandas' conventions.
:pr:`25629` by `Thomas Fan`_.

- |Fix| Fix deprecation of `base_estimator` in :class:`ensemble.AdaBoostClassifier`
and :class:`ensemble.AdaBoostRegressor` that was introduced in :pr:`23819`.
:pr:`26242` by :user:`Marko Toplak <markotoplak>`.

:mod:`sklearn.exception`
........................
- |Feature| Added :class:`exception.InconsistentVersionWarning` which is raised
Expand Down
7 changes: 5 additions & 2 deletions sklearn/ensemble/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,18 @@ def _validate_estimator(self, default=None):

if self.estimator is not None:
self.estimator_ = self.estimator
elif self.base_estimator not in [None, "deprecated"]:
elif self.base_estimator != "deprecated":
warnings.warn(
(
"`base_estimator` was renamed to `estimator` in version 1.2 and "
"will be removed in 1.4."
),
FutureWarning,
)
self.estimator_ = self.base_estimator
if self.base_estimator is not None:
self.estimator_ = self.base_estimator
else:
self.estimator_ = default
else:
self.estimator_ = default

Expand Down
6 changes: 5 additions & 1 deletion sklearn/ensemble/_weight_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ class BaseWeightBoosting(BaseEnsemble, metaclass=ABCMeta):
"n_estimators": [Interval(Integral, 1, None, closed="left")],
"learning_rate": [Interval(Real, 0, None, closed="neither")],
"random_state": ["random_state"],
"base_estimator": [HasMethods(["fit", "predict"]), StrOptions({"deprecated"})],
"base_estimator": [
HasMethods(["fit", "predict"]),
StrOptions({"deprecated"}),
None,
],
}

@abstractmethod
Expand Down
21 changes: 21 additions & 0 deletions sklearn/ensemble/tests/test_weight_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,27 @@ def test_base_estimator_argument_deprecated(AdaBoost, Estimator):
model.fit(X, y)


# TODO(1.4): remove in 1.4
@pytest.mark.parametrize(
"AdaBoost",
[
AdaBoostClassifier,
AdaBoostRegressor,
],
)
def test_base_estimator_argument_deprecated_none(AdaBoost):
X = np.array([[1, 2], [3, 4]])
y = np.array([1, 0])
model = AdaBoost(base_estimator=None)

warn_msg = (
"`base_estimator` was renamed to `estimator` in version 1.2 and "
"will be removed in 1.4."
)
with pytest.warns(FutureWarning, match=warn_msg):
model.fit(X, y)


# TODO(1.4): remove in 1.4
@pytest.mark.parametrize(
"AdaBoost",
Expand Down
0