From 7793726850408594a9249adbc41e999d5f19f627 Mon Sep 17 00:00:00 2001 From: Work Date: Tue, 6 Feb 2024 14:57:53 +0000 Subject: [PATCH 1/9] Fix `SGDRegressor` documentation --- sklearn/linear_model/_stochastic_gradient.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sklearn/linear_model/_stochastic_gradient.py b/sklearn/linear_model/_stochastic_gradient.py index aeec7b5588add..f32a3786d0af5 100644 --- a/sklearn/linear_model/_stochastic_gradient.py +++ b/sklearn/linear_model/_stochastic_gradient.py @@ -1789,9 +1789,9 @@ class SGDRegressor(BaseSGDRegressor): alpha : float, default=0.0001 Constant that multiplies the regularization term. The higher the - value, the stronger the regularization. - Also used to compute the learning rate when set to `learning_rate` is - set to 'optimal'. + value, the stronger the regularization. Also used to compute the + learning rate when `learning_rate` is set to 'optimal'. + Values must be in the range `[0.0, inf)`. l1_ratio : float, default=0.15 The Elastic Net mixing parameter, with 0 <= l1_ratio <= 1. From 38354686288054f53fa7e6a131e6f413a50b66ad Mon Sep 17 00:00:00 2001 From: Work Date: Tue, 6 Feb 2024 15:47:52 +0000 Subject: [PATCH 2/9] Include contraints in other parameters in the documentation --- sklearn/linear_model/_stochastic_gradient.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sklearn/linear_model/_stochastic_gradient.py b/sklearn/linear_model/_stochastic_gradient.py index f32a3786d0af5..346d86d26ce02 100644 --- a/sklearn/linear_model/_stochastic_gradient.py +++ b/sklearn/linear_model/_stochastic_gradient.py @@ -1797,6 +1797,7 @@ class SGDRegressor(BaseSGDRegressor): The Elastic Net mixing parameter, with 0 <= l1_ratio <= 1. l1_ratio=0 corresponds to L2 penalty, l1_ratio=1 to L1. Only used if `penalty` is 'elasticnet'. + Values must be in the range `[0.0, 1.0]`. fit_intercept : bool, default=True Whether the intercept should be estimated or not. If False, the @@ -1806,6 +1807,7 @@ class SGDRegressor(BaseSGDRegressor): The maximum number of passes over the training data (aka epochs). It only impacts the behavior in the ``fit`` method, and not the :meth:`partial_fit` method. + Values must be in the range `[1, inf)`. .. versionadded:: 0.19 @@ -1815,6 +1817,7 @@ class SGDRegressor(BaseSGDRegressor): epochs. Convergence is checked against the training loss or the validation loss depending on the `early_stopping` parameter. + Values must be in the range `[0.0, inf)`. .. versionadded:: 0.19 @@ -1823,6 +1826,7 @@ class SGDRegressor(BaseSGDRegressor): verbose : int, default=0 The verbosity level. + Values must be in the range `[0, inf)`. epsilon : float, default=0.1 Epsilon in the epsilon-insensitive loss functions; only if `loss` is @@ -1855,9 +1859,11 @@ class SGDRegressor(BaseSGDRegressor): eta0 : float, default=0.01 The initial learning rate for the 'constant', 'invscaling' or 'adaptive' schedules. The default value is 0.01. + Values must be in the range `(0.0, inf)`. power_t : float, default=0.25 The exponent for inverse scaling learning rate. + Values must be in the range `(-inf, inf)`. early_stopping : bool, default=False Whether to use early stopping to terminate training when validation @@ -1874,6 +1880,7 @@ class SGDRegressor(BaseSGDRegressor): The proportion of training data to set aside as validation set for early stopping. Must be between 0 and 1. Only used if `early_stopping` is True. + Values must be in the range `(0.0, 1.0)`. .. versionadded:: 0.20 Added 'validation_fraction' option @@ -1883,6 +1890,7 @@ class SGDRegressor(BaseSGDRegressor): fitting. Convergence is checked against the training loss or the validation loss depending on the `early_stopping` parameter. + Integer values must be in the range `[1, max_iter)`. .. versionadded:: 0.20 Added 'n_iter_no_change' option From 8262ebadb1e377c997acfa951987124d885dd560 Mon Sep 17 00:00:00 2001 From: Work Date: Tue, 6 Feb 2024 15:54:51 +0000 Subject: [PATCH 3/9] Remove awkward default value references --- sklearn/linear_model/_stochastic_gradient.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearn/linear_model/_stochastic_gradient.py b/sklearn/linear_model/_stochastic_gradient.py index 346d86d26ce02..101476fd60dbd 100644 --- a/sklearn/linear_model/_stochastic_gradient.py +++ b/sklearn/linear_model/_stochastic_gradient.py @@ -1064,7 +1064,7 @@ class SGDClassifier(BaseSGDClassifier): Values must be in the range `(0.0, inf)`. power_t : float, default=0.5 - The exponent for inverse scaling learning rate [default 0.5]. + The exponent for inverse scaling learning rate. Values must be in the range `(-inf, inf)`. early_stopping : bool, default=False @@ -2104,7 +2104,7 @@ class SGDOneClassSVM(BaseSGD, OutlierMixin): the default schedule 'optimal'. power_t : float, default=0.5 - The exponent for inverse scaling learning rate [default 0.5]. + The exponent for inverse scaling learning rate. warm_start : bool, default=False When set to True, reuse the solution of the previous call to fit as From cd02686e00152e4cb8673f05cbf0812d27ec814f Mon Sep 17 00:00:00 2001 From: Bruno <30274260+bmgdc@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:08:54 +0000 Subject: [PATCH 4/9] Implement https://github.com/scikit-learn/scikit-learn/pull/28373#discussion_r1482792532 Co-authored-by: Guillaume Lemaitre --- sklearn/linear_model/_stochastic_gradient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/linear_model/_stochastic_gradient.py b/sklearn/linear_model/_stochastic_gradient.py index 101476fd60dbd..10bf6269c6907 100644 --- a/sklearn/linear_model/_stochastic_gradient.py +++ b/sklearn/linear_model/_stochastic_gradient.py @@ -1859,7 +1859,7 @@ class SGDRegressor(BaseSGDRegressor): eta0 : float, default=0.01 The initial learning rate for the 'constant', 'invscaling' or 'adaptive' schedules. The default value is 0.01. - Values must be in the range `(0.0, inf)`. + Values must be in the range `[0.0, inf)`. power_t : float, default=0.25 The exponent for inverse scaling learning rate. From b1253fb962f26c27ccd6cb714b95db80a559fcb6 Mon Sep 17 00:00:00 2001 From: Work Date: Thu, 8 Feb 2024 11:10:28 +0000 Subject: [PATCH 5/9] Address https://github.com/scikit-learn/scikit-learn/pull/28373#pullrequestreview-1869859345 --- sklearn/linear_model/_stochastic_gradient.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sklearn/linear_model/_stochastic_gradient.py b/sklearn/linear_model/_stochastic_gradient.py index 10bf6269c6907..d1b007fe548bd 100644 --- a/sklearn/linear_model/_stochastic_gradient.py +++ b/sklearn/linear_model/_stochastic_gradient.py @@ -1835,6 +1835,7 @@ class SGDRegressor(BaseSGDRegressor): important to get the prediction exactly right. For epsilon-insensitive, any differences between the current prediction and the correct label are ignored if they are less than this threshold. + Values must be in the range `[0.0, inf)`. random_state : int, RandomState instance, default=None Used for shuffling the data, when ``shuffle`` is set to ``True``. From 6aa087da71dcde982e8c7028f1a28d9b085f84a7 Mon Sep 17 00:00:00 2001 From: Work Date: Thu, 8 Feb 2024 11:11:35 +0000 Subject: [PATCH 6/9] Address https://github.com/scikit-learn/scikit-learn/pull/28373#discussion_r1482793752 --- sklearn/linear_model/_stochastic_gradient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/linear_model/_stochastic_gradient.py b/sklearn/linear_model/_stochastic_gradient.py index d1b007fe548bd..4c4c8f6205d63 100644 --- a/sklearn/linear_model/_stochastic_gradient.py +++ b/sklearn/linear_model/_stochastic_gradient.py @@ -1061,7 +1061,7 @@ class SGDClassifier(BaseSGDClassifier): The initial learning rate for the 'constant', 'invscaling' or 'adaptive' schedules. The default value is 0.0 as eta0 is not used by the default schedule 'optimal'. - Values must be in the range `(0.0, inf)`. + Values must be in the range `[0.0, inf)`. power_t : float, default=0.5 The exponent for inverse scaling learning rate. From 97d5b4d2daa0400f5af52633ce3f0ab089c990b8 Mon Sep 17 00:00:00 2001 From: Work Date: Thu, 8 Feb 2024 11:35:25 +0000 Subject: [PATCH 7/9] Document default values in `SGDOneClassSVM` --- sklearn/linear_model/_stochastic_gradient.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sklearn/linear_model/_stochastic_gradient.py b/sklearn/linear_model/_stochastic_gradient.py index 4c4c8f6205d63..1826b0c83bb79 100644 --- a/sklearn/linear_model/_stochastic_gradient.py +++ b/sklearn/linear_model/_stochastic_gradient.py @@ -2067,10 +2067,12 @@ class SGDOneClassSVM(BaseSGD, OutlierMixin): The maximum number of passes over the training data (aka epochs). It only impacts the behavior in the ``fit`` method, and not the `partial_fit`. Defaults to 1000. + Values must be in the range `[1, inf)`. tol : float or None, default=1e-3 The stopping criterion. If it is not None, the iterations will stop when (loss > previous_loss - tol). Defaults to 1e-3. + Values must be in the range `[0.0, inf)`. shuffle : bool, default=True Whether or not the training data should be shuffled after each epoch. @@ -2103,9 +2105,11 @@ class SGDOneClassSVM(BaseSGD, OutlierMixin): The initial learning rate for the 'constant', 'invscaling' or 'adaptive' schedules. The default value is 0.0 as eta0 is not used by the default schedule 'optimal'. + Values must be in the range `[0.0, inf)`. power_t : float, default=0.5 The exponent for inverse scaling learning rate. + Values must be in the range `(-inf, inf)`. warm_start : bool, default=False When set to True, reuse the solution of the previous call to fit as From d181bda35cd5e7dcca9bce3366052625760fc14e Mon Sep 17 00:00:00 2001 From: Work Date: Thu, 8 Feb 2024 11:40:36 +0000 Subject: [PATCH 8/9] Fix/document `average` range values across the board --- sklearn/linear_model/_stochastic_gradient.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sklearn/linear_model/_stochastic_gradient.py b/sklearn/linear_model/_stochastic_gradient.py index 1826b0c83bb79..05348f221c8f4 100644 --- a/sklearn/linear_model/_stochastic_gradient.py +++ b/sklearn/linear_model/_stochastic_gradient.py @@ -1125,7 +1125,7 @@ class SGDClassifier(BaseSGDClassifier): an int greater than 1, averaging will begin once the total number of samples seen reaches `average`. So ``average=10`` will begin averaging after seeing 10 samples. - Integer values must be in the range `[1, n_samples]`. + Integer values must be in the range `[0, n_samples]`. Attributes ---------- @@ -1915,6 +1915,7 @@ class SGDRegressor(BaseSGDRegressor): an int greater than 1, averaging will begin once the total number of samples seen reaches `average`. So ``average=10`` will begin averaging after seeing 10 samples. + Integer values must be in the range `[0, n_samples]`. Attributes ---------- @@ -2130,6 +2131,7 @@ class SGDOneClassSVM(BaseSGD, OutlierMixin): averaging will begin once the total number of samples seen reaches average. So ``average=10`` will begin averaging after seeing 10 samples. + Integer values must be in the range `[0, n_samples]`. Attributes ---------- From d544717610fbc40c3c514d538ebc5f085158b043 Mon Sep 17 00:00:00 2001 From: Work Date: Thu, 8 Feb 2024 17:58:25 +0000 Subject: [PATCH 9/9] Revert "Fix/document `average` range values across the board" This reverts commit d181bda35cd5e7dcca9bce3366052625760fc14e. --- sklearn/linear_model/_stochastic_gradient.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sklearn/linear_model/_stochastic_gradient.py b/sklearn/linear_model/_stochastic_gradient.py index 05348f221c8f4..1826b0c83bb79 100644 --- a/sklearn/linear_model/_stochastic_gradient.py +++ b/sklearn/linear_model/_stochastic_gradient.py @@ -1125,7 +1125,7 @@ class SGDClassifier(BaseSGDClassifier): an int greater than 1, averaging will begin once the total number of samples seen reaches `average`. So ``average=10`` will begin averaging after seeing 10 samples. - Integer values must be in the range `[0, n_samples]`. + Integer values must be in the range `[1, n_samples]`. Attributes ---------- @@ -1915,7 +1915,6 @@ class SGDRegressor(BaseSGDRegressor): an int greater than 1, averaging will begin once the total number of samples seen reaches `average`. So ``average=10`` will begin averaging after seeing 10 samples. - Integer values must be in the range `[0, n_samples]`. Attributes ---------- @@ -2131,7 +2130,6 @@ class SGDOneClassSVM(BaseSGD, OutlierMixin): averaging will begin once the total number of samples seen reaches average. So ``average=10`` will begin averaging after seeing 10 samples. - Integer values must be in the range `[0, n_samples]`. Attributes ----------