bundles / scipy 1.17.1 / scipy / stats / _probability_distribution / _ProbabilityDistribution / mode
function
scipy.stats._probability_distribution:_ProbabilityDistribution.mode
Signature
def mode ( self , * , method ) Summary
Mode (most likely value)
Extended Summary
Informally, the mode is a value that a random variable has the highest probability (density) of assuming. That is, the mode is the element of the support that maximizes the probability density (or mass, for discrete random variables) function :
Parameters
method: {None, 'formula', 'optimization'}The strategy used to evaluate the mode. By default (
None), the infrastructure chooses between the following options, listed in order of precedence.'formula': use a formula for the median'optimization': numerically maximize the PDF/PMF
Not all
methodoptions are available for all distributions. If the selectedmethodis not available, aNotImplementedErrorwill be raised.
Returns
out: arrayThe mode
Notes
For some distributions
the mode is not unique (e.g. the uniform distribution);
the PDF has one or more singularities, and it is debatable whether a singularity is considered to be in the domain and called the mode (e.g. the gamma distribution with shape parameter less than 1); and/or
the probability density function may have one or more local maxima that are not a global maximum (e.g. mixture distributions).
In such cases, mode will
return a single value,
consider the mode to occur at a singularity, and/or
return a local maximum which may or may not be a global maximum.
If a formula for the mode is not specifically implemented for the chosen distribution, SciPy will attempt to compute the mode numerically, which may not meet the user's preferred definition of a mode. In such cases, the user is encouraged to subclass the distribution and override mode.
Examples
Instantiate a distribution with the desired parameters:from scipy import stats X = stats.Normal(mu=1., sigma=2.)✓
X.mode()
✗X = stats.Uniform(a=0., b=1.)
✓X.mode()
✗class BetterUniform(stats.Uniform): def mode(self): return self.b X = BetterUniform(a=0., b=1.)✓
X.mode()
✗See also
Aliases
-
scipy.stats._distribution_infrastructure._ProbabilityDistribution.mode