From 9d6805fdd5e9fe3f414b0ecc77cce8c18e42cf87 Mon Sep 17 00:00:00 2001 From: zeeshan Date: Wed, 1 Mar 2023 15:53:42 +0530 Subject: [PATCH 1/3] Added parameter validation for r_regression and added test to it --- sklearn/feature_selection/_univariate_selection.py | 8 ++++++++ sklearn/tests/test_public_functions.py | 1 + 2 files changed, 9 insertions(+) diff --git a/sklearn/feature_selection/_univariate_selection.py b/sklearn/feature_selection/_univariate_selection.py index 2868cf06ae02e..7146ffaa90b33 100644 --- a/sklearn/feature_selection/_univariate_selection.py +++ b/sklearn/feature_selection/_univariate_selection.py @@ -251,6 +251,14 @@ def chi2(X, y): return _chisquare(observed, expected) +@validate_params( + { + "X": ["array-like", "sparse matrix"], + "y": ["array-like"], + "center": [bool], + "force_finite": [bool], + } +) def r_regression(X, y, *, center=True, force_finite=True): """Compute Pearson's r for each features and the target. diff --git a/sklearn/tests/test_public_functions.py b/sklearn/tests/test_public_functions.py index b50e469f80a1e..6b8c2a30912fc 100644 --- a/sklearn/tests/test_public_functions.py +++ b/sklearn/tests/test_public_functions.py @@ -148,6 +148,7 @@ def _check_function_param_validation( "sklearn.model_selection.train_test_split", "sklearn.random_projection.johnson_lindenstrauss_min_dim", "sklearn.svm.l1_min_c", + "sklearn.feature_selection.r_regression", ] From 54dbe1c5db7368e6cf47cfd966e309a6e237cc94 Mon Sep 17 00:00:00 2001 From: zeeshan lone <56621467+still-learning-ev@users.noreply.github.com> Date: Sat, 4 Mar 2023 01:29:27 +0530 Subject: [PATCH 2/3] Update sklearn/feature_selection/_univariate_selection.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jérémie du Boisberranger <34657725+jeremiedbb@users.noreply.github.com> --- sklearn/feature_selection/_univariate_selection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearn/feature_selection/_univariate_selection.py b/sklearn/feature_selection/_univariate_selection.py index 7146ffaa90b33..feee5088ce092 100644 --- a/sklearn/feature_selection/_univariate_selection.py +++ b/sklearn/feature_selection/_univariate_selection.py @@ -255,8 +255,8 @@ def chi2(X, y): { "X": ["array-like", "sparse matrix"], "y": ["array-like"], - "center": [bool], - "force_finite": [bool], + "center": ["boolean"], + "force_finite": ["boolean"], } ) def r_regression(X, y, *, center=True, force_finite=True): From 63268b65404cc9e814097dd06ad359a41ef9e2fd Mon Sep 17 00:00:00 2001 From: zeeshan Date: Sat, 4 Mar 2023 14:42:46 +0530 Subject: [PATCH 3/3] moved the line for alphabetical ordering --- sklearn/tests/test_public_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/tests/test_public_functions.py b/sklearn/tests/test_public_functions.py index f25052b48be9d..d83a22d2780b6 100644 --- a/sklearn/tests/test_public_functions.py +++ b/sklearn/tests/test_public_functions.py @@ -115,6 +115,7 @@ def _check_function_param_validation( "sklearn.feature_extraction.image.reconstruct_from_patches_2d", "sklearn.feature_selection.chi2", "sklearn.feature_selection.f_classif", + "sklearn.feature_selection.r_regression", "sklearn.metrics.accuracy_score", "sklearn.metrics.auc", "sklearn.metrics.average_precision_score", @@ -151,7 +152,6 @@ def _check_function_param_validation( "sklearn.model_selection.train_test_split", "sklearn.random_projection.johnson_lindenstrauss_min_dim", "sklearn.svm.l1_min_c", - "sklearn.feature_selection.r_regression", ]