Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DOC Ensures that sklearn.utils.extmath.weighted_mode passes numpydoc validation #24571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion sklearn/tests/test_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 10 additions & 9 deletions sklearn/utils/extmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ 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.
Expand All @@ -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.

Expand All @@ -617,6 +617,11 @@ def weighted_mode(a, w, *, axis=0):
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
--------
>>> from sklearn.utils.extmath import weighted_mode
Expand All @@ -634,10 +639,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)
Expand Down