diff --git a/sklearn/linear_model/_stochastic_gradient.py b/sklearn/linear_model/_stochastic_gradient.py index 006bfc73da63e..ff6878d5e1686 100644 --- a/sklearn/linear_model/_stochastic_gradient.py +++ b/sklearn/linear_model/_stochastic_gradient.py @@ -158,14 +158,6 @@ def _more_validate_params(self, for_partial_fit=False): self._get_penalty_type(self.penalty) self._get_learning_rate_type(self.learning_rate) - # TODO(1.3): remove "log" - if self.loss == "log": - warnings.warn( - "The loss 'log' was deprecated in v1.1 and will be removed in version " - "1.3. Use `loss='log_loss'` which is equivalent.", - FutureWarning, - ) - def _get_loss_function(self, loss): """Get concrete ``LossFunction`` object for str ``loss``.""" loss_ = self.loss_functions[loss] @@ -501,13 +493,11 @@ def _get_plain_sgd_function(input_dtype): class BaseSGDClassifier(LinearClassifierMixin, BaseSGD, metaclass=ABCMeta): - # TODO(1.3): Remove "log"" loss_functions = { "hinge": (Hinge, 1.0), "squared_hinge": (SquaredHinge, 1.0), "perceptron": (Hinge, 0.0), "log_loss": (Log,), - "log": (Log,), "modified_huber": (ModifiedHuber,), "squared_error": (SquaredLoss,), "huber": (Huber, DEFAULT_EPSILON), @@ -517,7 +507,7 @@ class BaseSGDClassifier(LinearClassifierMixin, BaseSGD, metaclass=ABCMeta): _parameter_constraints: dict = { **BaseSGD._parameter_constraints, - "loss": [StrOptions(set(loss_functions), deprecated={"log"})], + "loss": [StrOptions(set(loss_functions))], "early_stopping": ["boolean"], "validation_fraction": [Interval(Real, 0, 1, closed="neither")], "n_iter_no_change": [Interval(Integral, 1, None, closed="left")], @@ -950,7 +940,7 @@ class SGDClassifier(BaseSGDClassifier): Parameters ---------- - loss : {'hinge', 'log_loss', 'log', 'modified_huber', 'squared_hinge',\ + loss : {'hinge', 'log_loss', 'modified_huber', 'squared_hinge',\ 'perceptron', 'squared_error', 'huber', 'epsilon_insensitive',\ 'squared_epsilon_insensitive'}, default='hinge' The loss function to be used. @@ -958,7 +948,7 @@ class SGDClassifier(BaseSGDClassifier): - 'hinge' gives a linear SVM. - 'log_loss' gives logistic regression, a probabilistic classifier. - 'modified_huber' is another smooth loss that brings tolerance to - outliers as well as probability estimates. + outliers as well as probability estimates. - 'squared_hinge' is like hinge but is quadratically penalized. - 'perceptron' is the linear loss used by the perceptron algorithm. - The other losses, 'squared_error', 'huber', 'epsilon_insensitive' and @@ -969,10 +959,6 @@ class SGDClassifier(BaseSGDClassifier): More details about the losses formulas can be found in the :ref:`User Guide `. - .. deprecated:: 1.1 - The loss 'log' was deprecated in v1.1 and will be removed - in version 1.3. Use `loss='log_loss'` which is equivalent. - penalty : {'l2', 'l1', 'elasticnet', None}, default='l2' The penalty (aka regularization term) to be used. Defaults to 'l2' which is the standard regularizer for linear SVM models. 'l1' and @@ -1249,8 +1235,7 @@ def __init__( ) def _check_proba(self): - # TODO(1.3): Remove "log" - if self.loss not in ("log_loss", "log", "modified_huber"): + if self.loss not in ("log_loss", "modified_huber"): raise AttributeError( "probability estimates are not available for loss=%r" % self.loss ) @@ -1295,8 +1280,7 @@ def predict_proba(self, X): """ check_is_fitted(self) - # TODO(1.3): Remove "log" - if self.loss in ("log_loss", "log"): + if self.loss == "log_loss": return self._predict_proba_lr(X) elif self.loss == "modified_huber": diff --git a/sklearn/linear_model/tests/test_sgd.py b/sklearn/linear_model/tests/test_sgd.py index c5f0d4507227e..51c166869f174 100644 --- a/sklearn/linear_model/tests/test_sgd.py +++ b/sklearn/linear_model/tests/test_sgd.py @@ -716,8 +716,7 @@ def test_sgd_predict_proba_method_access(klass): # details. for loss in linear_model.SGDClassifier.loss_functions: clf = SGDClassifier(loss=loss) - # TODO(1.3): Remove "log" - if loss in ("log_loss", "log", "modified_huber"): + if loss in ("log_loss", "modified_huber"): assert hasattr(clf, "predict_proba") assert hasattr(clf, "predict_log_proba") else: @@ -2060,29 +2059,6 @@ def test_SGDClassifier_fit_for_all_backends(backend): assert_array_almost_equal(clf_sequential.coef_, clf_parallel.coef_) -# TODO(1.3): Remove -@pytest.mark.parametrize( - "old_loss, new_loss, Estimator", - [ - ("log", "log_loss", linear_model.SGDClassifier), - ], -) -def test_loss_deprecated(old_loss, new_loss, Estimator): - - # Note: class BaseSGD calls self._validate_params() in __init__, therefore - # even instantiation of class raises FutureWarning for deprecated losses. - with pytest.warns(FutureWarning, match=f"The loss '{old_loss}' was deprecated"): - est1 = Estimator(loss=old_loss, random_state=0) - est1.fit(X, Y) - - est2 = Estimator(loss=new_loss, random_state=0) - est2.fit(X, Y) - if hasattr(est1, "predict_proba"): - assert_allclose(est1.predict_proba(X), est2.predict_proba(X)) - else: - assert_allclose(est1.predict(X), est2.predict(X)) - - @pytest.mark.parametrize( "Estimator", [linear_model.SGDClassifier, linear_model.SGDRegressor] )