From 82caf7013c8266034c70643478e0efaa6099a584 Mon Sep 17 00:00:00 2001 From: awinml <97467100+awinml@users.noreply.github.com> Date: Tue, 4 Oct 2022 09:11:29 +0530 Subject: [PATCH 1/5] Ensures that sklearn.utils.extmath.weighted_mode passes numpydoc_validation --- sklearn/tests/test_docstrings.py | 2 +- sklearn/utils/extmath.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sklearn/tests/test_docstrings.py b/sklearn/tests/test_docstrings.py index ee9f412647bbb..fab9ea22b77ad 100644 --- a/sklearn/tests/test_docstrings.py +++ b/sklearn/tests/test_docstrings.py @@ -16,7 +16,7 @@ "sklearn.utils.extmath.randomized_svd", "sklearn.utils.extmath.safe_sparse_dot", "sklearn.utils.extmath.svd_flip", - "sklearn.utils.extmath.weighted_mode", + #"sklearn.utils.extmath.weighted_mode", "sklearn.utils.fixes.delayed", "sklearn.utils.fixes.linspace", # To be fixed in upstream issue: diff --git a/sklearn/utils/extmath.py b/sklearn/utils/extmath.py index 02ab65fe05293..625b322d89ae1 100644 --- a/sklearn/utils/extmath.py +++ b/sklearn/utils/extmath.py @@ -594,8 +594,8 @@ def _randomized_eigsh( def weighted_mode(a, w, *, axis=0): - """Returns an array of the weighted modal (most common) value in a. - + """Return an array of the weighted modal (most common) value in the passed array. + If there is more than one such value, only the first is returned. The bin-count for the modal bins is also returned. @@ -603,10 +603,10 @@ def weighted_mode(a, w, *, axis=0): Parameters ---------- - a : array-like - n-dimensional array of which to find mode(s). - w : array-like - n-dimensional array of weights for each value. + a : array-like of shape (n_samples,) + Array of which values to find mode(s). + w : array-like of shape (n_samples,) + Array of weights for each value. axis : int, default=0 Axis along which to operate. Default is 0, i.e. the first axis. @@ -616,6 +616,10 @@ def weighted_mode(a, w, *, axis=0): Array of modal values. score : ndarray Array of weighted counts for each mode. + + See Also + -------- + scipy.stats.mode: Calculates the Modal (most common) value of array elements along specified axis. Examples -------- @@ -634,10 +638,6 @@ def weighted_mode(a, w, *, axis=0): The value 2 has the highest score: it appears twice with weights of 1.5 and 2: the sum of these is 3.5. - - See Also - -------- - scipy.stats.mode """ if axis is None: a = np.ravel(a) From 0c5cea38e44e43a3c3cbff5346a46d225e72c32c Mon Sep 17 00:00:00 2001 From: awinml <97467100+awinml@users.noreply.github.com> Date: Tue, 4 Oct 2022 09:16:04 +0530 Subject: [PATCH 2/5] Ensures that sklearn.utils.extmath.weighted_mode passes numpydoc_validation --- sklearn/tests/test_docstrings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sklearn/tests/test_docstrings.py b/sklearn/tests/test_docstrings.py index fab9ea22b77ad..5c8c52bb8d24c 100644 --- a/sklearn/tests/test_docstrings.py +++ b/sklearn/tests/test_docstrings.py @@ -16,7 +16,6 @@ "sklearn.utils.extmath.randomized_svd", "sklearn.utils.extmath.safe_sparse_dot", "sklearn.utils.extmath.svd_flip", - #"sklearn.utils.extmath.weighted_mode", "sklearn.utils.fixes.delayed", "sklearn.utils.fixes.linspace", # To be fixed in upstream issue: From 8d2532b82c5142b192c607e3b568055a076bf6fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20du=20Boisberranger?= <34657725+jeremiedbb@users.noreply.github.com> Date: Fri, 7 Oct 2022 10:58:07 +0200 Subject: [PATCH 3/5] Update extmath.py --- sklearn/utils/extmath.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/utils/extmath.py b/sklearn/utils/extmath.py index 625b322d89ae1..bddd9e580b355 100644 --- a/sklearn/utils/extmath.py +++ b/sklearn/utils/extmath.py @@ -595,7 +595,7 @@ def _randomized_eigsh( def weighted_mode(a, w, *, axis=0): """Return an array of the weighted modal (most common) value in the passed array. - + If there is more than one such value, only the first is returned. The bin-count for the modal bins is also returned. From 14406abacae9f540a66eed0afbf71d554b2dea32 Mon Sep 17 00:00:00 2001 From: jeremie du boisberranger Date: Fri, 7 Oct 2022 11:38:47 +0200 Subject: [PATCH 4/5] lint --- sklearn/utils/extmath.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/utils/extmath.py b/sklearn/utils/extmath.py index bddd9e580b355..72a1166015d6e 100644 --- a/sklearn/utils/extmath.py +++ b/sklearn/utils/extmath.py @@ -616,7 +616,7 @@ def weighted_mode(a, w, *, axis=0): Array of modal values. score : ndarray Array of weighted counts for each mode. - + See Also -------- scipy.stats.mode: Calculates the Modal (most common) value of array elements along specified axis. From 8b447a9f5d6855e903224dde4b021380f085e6d8 Mon Sep 17 00:00:00 2001 From: jeremie du boisberranger Date: Fri, 7 Oct 2022 11:56:07 +0200 Subject: [PATCH 5/5] lint --- sklearn/utils/extmath.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sklearn/utils/extmath.py b/sklearn/utils/extmath.py index 72a1166015d6e..6110303e3adc9 100644 --- a/sklearn/utils/extmath.py +++ b/sklearn/utils/extmath.py @@ -619,7 +619,8 @@ def weighted_mode(a, w, *, axis=0): See Also -------- - scipy.stats.mode: Calculates the Modal (most common) value of array elements along specified axis. + scipy.stats.mode: Calculates the Modal (most common) value of array elements + along specified axis. Examples --------