From 74fcce3d000838e499f7adf71445cb331e5b0494 Mon Sep 17 00:00:00 2001 From: Sangam <35230623+SangamSwadiK@users.noreply.github.com> Date: Sat, 11 Jun 2022 09:21:24 +0530 Subject: [PATCH 1/6] Remove Robust Scaler Remove Robust Scaler from to be validated --- 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 17ad851a3d7bd..89317bfd6945a 100644 --- a/sklearn/tests/test_common.py +++ b/sklearn/tests/test_common.py @@ -600,7 +600,6 @@ def test_estimators_do_not_raise_errors_in_init_or_set_params(Estimator): "RidgeCV", "RidgeClassifier", "RidgeClassifierCV", - "RobustScaler", "SGDClassifier", "SGDOneClassSVM", "SGDRegressor", From c2d0b353c0f80a7b7da2e194f2bbabc148c29d4b Mon Sep 17 00:00:00 2001 From: Sangam <35230623+SangamSwadiK@users.noreply.github.com> Date: Sat, 11 Jun 2022 09:52:04 +0530 Subject: [PATCH 2/6] Add validation to Robust scaler Add validation to robust scaler and check for validation in fit. --- sklearn/preprocessing/_data.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sklearn/preprocessing/_data.py b/sklearn/preprocessing/_data.py index f0088aab521ad..fa0d1974cbb09 100644 --- a/sklearn/preprocessing/_data.py +++ b/sklearn/preprocessing/_data.py @@ -1447,7 +1447,15 @@ class RobustScaler(_OneToOneFeatureMixin, TransformerMixin, BaseEstimator): [-1. , 0. , 0.4], [ 1. , 0. , -1.6]]) """ - + + _parameter_constraints = { + "with_centering":[bool], + "with_scaling":[bool], + "quantile_range":["array-like"], + "copy":[bool], + "unit_variance":[bool] + } + def __init__( self, *, @@ -1482,6 +1490,8 @@ def fit(self, X, y=None): """ # at fit, convert sparse matrices to csc for optimized computation of # the quantiles + self._validate_params() + X = self._validate_data( X, accept_sparse="csc", From ee9ba5540a13e997c6661e260f06e33ca536302c Mon Sep 17 00:00:00 2001 From: Sangam Swadi K Date: Sat, 11 Jun 2022 09:59:12 +0530 Subject: [PATCH 3/6] reformat for linting --- sklearn/preprocessing/_data.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sklearn/preprocessing/_data.py b/sklearn/preprocessing/_data.py index fa0d1974cbb09..6dd3c7d129477 100644 --- a/sklearn/preprocessing/_data.py +++ b/sklearn/preprocessing/_data.py @@ -1447,15 +1447,15 @@ class RobustScaler(_OneToOneFeatureMixin, TransformerMixin, BaseEstimator): [-1. , 0. , 0.4], [ 1. , 0. , -1.6]]) """ - + _parameter_constraints = { - "with_centering":[bool], - "with_scaling":[bool], - "quantile_range":["array-like"], - "copy":[bool], - "unit_variance":[bool] + "with_centering": [bool], + "with_scaling": [bool], + "quantile_range": ["array-like"], + "copy": [bool], + "unit_variance": [bool], } - + def __init__( self, *, @@ -1491,7 +1491,7 @@ def fit(self, X, y=None): # at fit, convert sparse matrices to csc for optimized computation of # the quantiles self._validate_params() - + X = self._validate_data( X, accept_sparse="csc", From 4cf7518b7a53bc2e5a57842e00cc4bf455e9da36 Mon Sep 17 00:00:00 2001 From: Sangam Swadi K Date: Mon, 13 Jun 2022 10:22:46 +0530 Subject: [PATCH 4/6] fix quantile range type --- sklearn/preprocessing/_data.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sklearn/preprocessing/_data.py b/sklearn/preprocessing/_data.py index 6dd3c7d129477..f7113c38d5fc7 100644 --- a/sklearn/preprocessing/_data.py +++ b/sklearn/preprocessing/_data.py @@ -9,6 +9,7 @@ import warnings +from numbers import Real import numpy as np from scipy import sparse @@ -24,6 +25,7 @@ ) from ..utils import check_array from ..utils.extmath import _incremental_mean_and_var, row_norms +from ..utils._param_validation import Interval from ..utils.sparsefuncs_fast import ( inplace_csr_row_normalize_l1, inplace_csr_row_normalize_l2, @@ -1451,7 +1453,10 @@ class RobustScaler(_OneToOneFeatureMixin, TransformerMixin, BaseEstimator): _parameter_constraints = { "with_centering": [bool], "with_scaling": [bool], - "quantile_range": ["array-like"], + "quantile_range": [ + Interval(Real, 0, 100, closed="both"), + Interval(Real, 0, 100, closed="both"), + ], "copy": [bool], "unit_variance": [bool], } From 9ba535dee1a64a911be9f25f2c4798499260c23b Mon Sep 17 00:00:00 2001 From: Sangam Swadi K Date: Mon, 13 Jun 2022 11:00:14 +0530 Subject: [PATCH 5/6] reverted back to array type --- sklearn/preprocessing/_data.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/sklearn/preprocessing/_data.py b/sklearn/preprocessing/_data.py index f7113c38d5fc7..c043a77235f10 100644 --- a/sklearn/preprocessing/_data.py +++ b/sklearn/preprocessing/_data.py @@ -9,7 +9,7 @@ import warnings -from numbers import Real + import numpy as np from scipy import sparse @@ -25,7 +25,6 @@ ) from ..utils import check_array from ..utils.extmath import _incremental_mean_and_var, row_norms -from ..utils._param_validation import Interval from ..utils.sparsefuncs_fast import ( inplace_csr_row_normalize_l1, inplace_csr_row_normalize_l2, @@ -1453,10 +1452,7 @@ class RobustScaler(_OneToOneFeatureMixin, TransformerMixin, BaseEstimator): _parameter_constraints = { "with_centering": [bool], "with_scaling": [bool], - "quantile_range": [ - Interval(Real, 0, 100, closed="both"), - Interval(Real, 0, 100, closed="both"), - ], + "quantile_range": ["array-like"], "copy": [bool], "unit_variance": [bool], } From 6f853610c4ffe5b071bcfde6f2f50d05a17e18aa Mon Sep 17 00:00:00 2001 From: jeremie du boisberranger Date: Fri, 24 Jun 2022 17:04:36 +0200 Subject: [PATCH 6/6] boolean --- sklearn/preprocessing/_data.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/sklearn/preprocessing/_data.py b/sklearn/preprocessing/_data.py index c043a77235f10..e36bb0206dd3a 100644 --- a/sklearn/preprocessing/_data.py +++ b/sklearn/preprocessing/_data.py @@ -10,7 +10,6 @@ import warnings - import numpy as np from scipy import sparse from scipy import stats @@ -1450,11 +1449,11 @@ class RobustScaler(_OneToOneFeatureMixin, TransformerMixin, BaseEstimator): """ _parameter_constraints = { - "with_centering": [bool], - "with_scaling": [bool], - "quantile_range": ["array-like"], - "copy": [bool], - "unit_variance": [bool], + "with_centering": ["boolean"], + "with_scaling": ["boolean"], + "quantile_range": [tuple], + "copy": ["boolean"], + "unit_variance": ["boolean"], } def __init__( @@ -1489,10 +1488,10 @@ def fit(self, X, y=None): self : object Fitted scaler. """ - # at fit, convert sparse matrices to csc for optimized computation of - # the quantiles self._validate_params() + # at fit, convert sparse matrices to csc for optimized computation of + # the quantiles X = self._validate_data( X, accept_sparse="csc",