From ccc861c9ddb2161c026d59a88fe7e36f2c8c6fc3 Mon Sep 17 00:00:00 2001 From: iofall <50991099+iofall@users.noreply.github.com> Date: Fri, 10 Dec 2021 22:41:42 +0530 Subject: [PATCH 1/3] Remove validation from __init__ for SGDOneClassSVM Co-authored-by: iofall <50991099+iofall@users.noreply.github.com> Co-authored-by: arisayosh <15692997+arisayosh@users.noreply.github.com> --- sklearn/linear_model/_stochastic_gradient.py | 6 +++--- sklearn/tests/test_common.py | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/sklearn/linear_model/_stochastic_gradient.py b/sklearn/linear_model/_stochastic_gradient.py index c07232b6c23fe..f28936d528956 100644 --- a/sklearn/linear_model/_stochastic_gradient.py +++ b/sklearn/linear_model/_stochastic_gradient.py @@ -2098,7 +2098,7 @@ def __init__( average=False, ): - alpha = nu / 2 + alpha = None self.nu = nu super(SGDOneClassSVM, self).__init__( loss="hinge", @@ -2305,8 +2305,8 @@ def partial_fit(self, X, y=None, sample_weight=None): Returns a fitted instance of self. """ - alpha = self.nu / 2 self._validate_params(for_partial_fit=True) + alpha = self.nu / 2 return self._partial_fit( X, @@ -2331,7 +2331,6 @@ def _fit( offset_init=None, sample_weight=None, ): - self._validate_params() if self.warm_start and hasattr(self, "coef_"): if coef_init is None: @@ -2404,6 +2403,7 @@ def fit(self, X, y=None, coef_init=None, offset_init=None, sample_weight=None): Returns a fitted instance of self. """ + self._validate_params() alpha = self.nu / 2 self._fit( X, diff --git a/sklearn/tests/test_common.py b/sklearn/tests/test_common.py index 8b0796b2b5dbc..f2ea871b3ac64 100644 --- a/sklearn/tests/test_common.py +++ b/sklearn/tests/test_common.py @@ -429,7 +429,6 @@ def test_transformers_get_feature_names_out(transformer): "GridSearchCV", "HalvingGridSearchCV", "Pipeline", - "SGDOneClassSVM", "TheilSenRegressor", "TweedieRegressor", ] From b4a782a64d41407e019807e3f7b6bb3087130733 Mon Sep 17 00:00:00 2001 From: iofall <50991099+iofall@users.noreply.github.com> Date: Sat, 11 Dec 2021 22:47:39 +0530 Subject: [PATCH 2/3] Resolve merge conflicts Co-authored-by: arisayosh <15692997+arisayosh@users.noreply.github.com> Co-authored-by: iofall <50991099+iofall@users.noreply.github.com> --- sklearn/tests/test_common.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sklearn/tests/test_common.py b/sklearn/tests/test_common.py index f2ea871b3ac64..6dbaafbc9e3eb 100644 --- a/sklearn/tests/test_common.py +++ b/sklearn/tests/test_common.py @@ -428,7 +428,6 @@ def test_transformers_get_feature_names_out(transformer): "FeatureUnion", "GridSearchCV", "HalvingGridSearchCV", - "Pipeline", "TheilSenRegressor", "TweedieRegressor", ] From 321b7916f0a6fd7408b863919e3b6af89228de2c Mon Sep 17 00:00:00 2001 From: iofall <50991099+iofall@users.noreply.github.com> Date: Sat, 11 Dec 2021 23:28:13 +0530 Subject: [PATCH 3/3] Add Changelog Co-authored-by: arisayosh <15692997+arisayosh@users.noreply.github.com> Co-authored-by: iofall <50991099+iofall@users.noreply.github.com> --- doc/whats_new/v1.1.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/whats_new/v1.1.rst b/doc/whats_new/v1.1.rst index 37dc4c56dc860..453c124cdb741 100644 --- a/doc/whats_new/v1.1.rst +++ b/doc/whats_new/v1.1.rst @@ -229,6 +229,11 @@ Changelog :pr:`21481` by :user:`Guillaume Lemaitre ` and :user:`Andrés Babino `. +- |Fix| :class:`linear_model.SGDOneClassSVM` now does not validate in + `__init__`. All the validation is now handled through `fit()` and + `partial_fit()`. + :pr:`21944` by :user:`Yogendrasingh ` and :user: `Arisa Y. ` + :mod:`sklearn.metrics` ......................