Array of which values to find mode(s).
w : array-like of shape (n_samples,)Array of weights for each value.
axis : int, default=0Axis along which to operate. Default is 0, i.e. the first axis.
Returns:
- vals : ndarray
Array of modal values.
- score : ndarray
Array of weighted counts for each mode.
Examples
from sklearn.utils.extmath import weighted_mode
x = [4, 1, 4, 2, 4, 2]
weights = [1, 1, 1, 1, 1, 1]
weighted_mode(x, weights)
(array([4.]), array([3.]))
The value 4 appears three times: with uniform weights, the result is
simply the mode of the distribution.
weights = [1, 3, 0.5, 1.5, 1, 2]
weighted_mode(x, weights)
(array([2.]), array([3.5]))
The value 2 has the highest score: it appears twice with weights of
1.5 and 2: the sum of these is 3.5.