8000 [MRG] DEP deprecate "mae" criterion in GadientBoosting estimators by madhuracj · Pull Request #18326 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG] DEP deprecate "mae" criterion in GadientBoosting estimators #18326

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 4 commits into from
Sep 4, 2020
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
5 changes: 5 additions & 0 deletions doc/whats_new/v0.24.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ Changelog
:class:`ensemble.GradientBoostingRegressor` and returns `1`.
:pr:`17702` by :user:`Simona Maggio <simonamaggio>`.

- |API|: Mean absolute error ('mae') is now deprecated for the parameter
``criterion`` in :class:`ensemble.GradientBoostingRegressor` and
:class:`ensemble.GradientBoostingClassifier`.
:pr:`18326` by :user:`Madhura Jayaratne <madhuracj>`.

:mod:`sklearn.exceptions`
.........................

Expand Down
31 changes: 31 additions & 0 deletions sklearn/ensemble/_gb.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ def _check_initialized(self):
"""Check that the estimator is initialized, raising an error if not."""
check_is_fitted(self)

@abstractmethod
def _warn_mae_for_criterion(self):
pass

def fit(self, X, y, sample_weight=None, monitor=None):
"""Fit the gradient boosting model.

Expand Down Expand Up @@ -393,6 +397,10 @@ def fit(self, X, y, sample_weight=None, monitor=None):
-------
self : object
"""
if self.criterion == 'mae':
# TODO: This should raise an error from 0.26
self._warn_mae_for_criterion()

# if not warmstart - clear the estimator state
if not self.warm_start:
self._clear_state()
Expand Down Expand Up @@ -802,6 +810,10 @@ class GradientBoostingClassifier(ClassifierMixin, BaseGradientBoosting):
some cases.

.. versionadded:: 0.18
.. deprecated:: 0.24
`criterion='mae'` is deprecated and will be removed in version
0.26. Use `criterion='friedman_mse'` or `'mse'` instead, as trees
should use a least-square criterion in Gradient Boosting.

min_samples_split : int or float, default=2
The minimum number of samples required to split an internal node:
Expand Down Expand Up @@ -1102,6 +1114,14 @@ def _validate_y(self, y, sample_weight):
self.n_classes_ = self._n_classes
return y

def _warn_mae_for_criterion(self):
# TODO: This should raise an error from 0.26
warnings.warn("criterion='mae' was deprecated in version 0.24 and "
"will be removed in version 0.26. Use "
"criterion='friedman_mse' or 'mse' instead, as trees "
"should use a least-square criterion in Gradient "
"Boosting.", FutureWarning)

def decision_function(self, X):
"""Compute the decision function of ``X``.

Expand Down Expand Up @@ -1320,6 +1340,10 @@ class GradientBoostingRegressor(RegressorMixin, BaseGradientBoosting):
some cases.

.. versionadded:: 0.18
.. deprecated:: 0.24
`criterion='mae'` is deprecated and will be removed in version
0.26. The correct way of minimizing the absolute error is to use
`loss='lad'` instead.

min_samples_split : int or float, default=2
The minimum number of samples required to split an internal node:
Expand Down Expand Up @@ -1601,6 +1625,13 @@ def _validate_y(self, y, sample_weight=None):
y = y.astype(DOUBLE)
return y

def _warn_mae_for_criterion(self):
# TODO: This should raise an error from 0.26
warnings.warn("criterion='mae' was deprecated in version 0.24 and "
"will be removed in version 0.26. The correct way of "
"minimizing the absolute error is to use loss='lad' "
"instead.", FutureWarning)

def predict(self, X):
"""Predict regression target for X.

Expand Down
14 changes: 14 additions & 0 deletions sklearn/ensemble/tests/test_gradient_boosting.py
583D
Original file line number Diff line number Diff line change
Expand Up @@ -1333,3 +1333,17 @@ def test_attr_error_raised_if_not_fitted():
)
with pytest.raises(AttributeError, match=msg):
gbr.n_classes_


# TODO: Update in 0.26 to check for the error raised
@pytest.mark.parametrize('estimator', [
GradientBoostingClassifier(criterion='mae'),
GradientBoostingRegressor(criterion='mae')
])
def test_criterion_mae_deprecation(estimator):
# checks whether a deprecation warning is issues when criterion='mae'
# is used.
msg = ("criterion='mae' was deprecated in version 0.24 and "
"will be removed in version 0.26.")
with pytest.warns(FutureWarning, match=msg):
estimator.fit(X, y)
0