Normal
- class scipy.stats.Normal(mu=None, sigma=None, **kwargs)
Normal distribution with prescribed mean and standard deviation.
The probability density function of the normal distribution is:
Normal distribution with prescribed mean and standard deviation.
The probability density function of the normal distribution is:
The desired relative tolerance of calculations. Left unspecified, calculations may be faster; when provided, calculations may be more likely to meet the desired accuracy.
Specifies the level of input validation to perform. Left unspecified,
input validation is performed to ensure appropriate behavior in edge
case (e.g. parameters out of domain, argument outside of distribution
support, etc.) and improve consistency of output dtype, shape, etc.
Pass 'skip_all' to avoid the computational overhead of these
checks when rough edges are acceptable.
Specifies the extent to which intermediate results are cached. Left
unspecified, intermediate results of some calculations (e.g. distribution
support, moments, etc.) are cached to improve performance of future
calculations. Pass 'no_cache' to reduce memory reserved by the class
instance.
| Support of the random variable |
| Plot a function of the distribution. |
| Random sample from the distribution. |
| Raw, central, or standard moment of positive integer order. |
| L-moment or L-moment ratio of positive integer order. |
| Mean (raw first moment about the origin) |
| Median (50th percentile) |
| Mode (most likely value) |
| Variance (central second moment) |
| Standard deviation (square root of the second central moment) |
| Skewness (standardized third moment) |
| Kurtosis (standardized fourth moment) |
| Probability density function |
| Log of the probability density function |
| Cumulative distribution function |
| Inverse of the cumulative distribution function. |
| Complementary cumulative distribution function |
| Inverse complementary cumulative distribution function. |
| Log of the cumulative distribution function |
| Inverse of the logarithm of the cumulative distribution function. |
| Log of the complementary cumulative distribution function |
| Inverse of the log of the complementary cumulative distribution function. |
| Differential entropy |
| Logarithm of the differential entropy |
The following abbreviations are used throughout the documentation.
PDF: probability density function
CDF: cumulative distribution function
CCDF: complementary CDF
entropy: differential entropy
log-F: logarithm of F (e.g. log-CDF)
inverse F: inverse function of F (e.g. inverse CDF)
The API documentation is written to describe the API, not to serve as a statistical reference. Effort is made to be correct at the level required to use the functionality, not to be mathematically rigorous. For example, continuity and differentiability may be implicitly assumed. For precise mathematical definitions, consult your preferred mathematical text.
To use the distribution class, it must be instantiated using keyword parameters corresponding with one of the accepted parameterizations.
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy import stats
>>> from scipy.stats import Normal
>>> X = Normal(mu=-0.81, sigma=0.69)
For convenience, the plot method can be used to visualize the density
and other functions of the distribution.
>>> X.plot()
>>> plt.show()
The support of the underlying distribution is available using the support
method.
>>> X.support()
(np.float64(-inf), np.float64(inf))
The numerical values of parameters associated with all parameterizations are available as attributes.
>>> X.mu, X.sigma
(np.float64(-0.81), np.float64(0.69))
To evaluate the probability density/mass function of the underlying distribution
at argument x=-1.13:
>>> x = -1.13
>>> X.pdf(x), X.pmf(x)
(np.float64(0.5192263911374636), np.float64(0.0))
The cumulative distribution function, its complement, and the logarithm of these functions are evaluated similarly.
>>> np.allclose(np.exp(X.logccdf(x)), 1 - X.cdf(x))
True
The inverse of these functions with respect to the argument x is also
available.
>>> logp = np.log(1 - X.ccdf(x))
>>> np.allclose(X.ilogcdf(logp), x)
True
Note that distribution functions and their logarithms also have two-argument versions for working with the probability mass between two arguments. The result tends to be more accurate than the naive implementation because it avoids subtractive cancellation.
>>> y = -0.56
>>> np.allclose(X.ccdf(x, y), 1 - (X.cdf(y) - X.cdf(x)))
True
There are methods for computing measures of central tendency, dispersion, higher moments, and entropy.
>>> X.mean(), X.median(), X.mode()
(np.float64(-0.81), np.float64(-0.81), np.float64(-0.81))
>>> X.variance(), X.standard_deviation()
(np.float64(0.4760999999999999), np.float64(0.69))
>>> X.skewness(), X.kurtosis()
(np.float64(0.0), np.float64(3.0))
>>> np.allclose(X.moment(order=6, kind='standardized'),
... X.moment(order=6, kind='central') / X.variance()
>>> np.allclose(np.exp(X.logentropy()), X.entropy())
True
Pseudo-random samples can be drawn from
the underlying distribution using sample.
>>> X.sample(shape=(4,))
array([-0.1330259 , 1.02258939, -1.95101232, -0.44946517]) # may vary