Representation of a kernel-density estimate using Gaussian kernels.
Kernel density estimation is a way to estimate the probability density
function (PDF) of a random variable in a non-parametric way.
gaussian_kde works for both uni-variate and multi-variate data. It
includes automatic bandwidth determination. The estimation works best for
a unimodal distribution; bimodal or multi-modal distributions tend to be
oversmoothed.
Parameters:
datasetarray_like
Datapoints to estimate from. In case of univariate data this is a 1-D
array, otherwise a 2-D array with shape (# of dims, # of data).
bw_methodstr, scalar or callable, optional
The method used to calculate the bandwidth factor. This can be
‘scott’, ‘silverman’, a scalar constant or a callable. If a scalar,
this will be used directly as factor. If a callable, it should
take a gaussian_kde instance as only parameter and return a scalar.
If None (default), ‘scott’ is used. See Notes for more details.
weightsarray_like, optional
weights of datapoints. This must be the same shape as dataset.
If None (default), the samples are assumed to be equally weighted
Attributes:
datasetndarray
The dataset with which gaussian_kde was initialized.
Bandwidth selection strongly influences the estimate obtained from the KDE
(much more so than the actual shape of the kernel). Bandwidth selection
can be done by a "rule of thumb", by cross-validation, by "plug-in
methods" or by other means; see [3], [4] for reviews. gaussian_kde
uses a rule of thumb, the default is Scott’s Rule.
with n the number of data points and d the number of dimensions.
In the case of unequally weighted points, scotts_factor becomes:
neff**(-1./(d+4)),
with neff the effective number of datapoints.
Silverman’s suggestion for multivariate data [2], implemented as
silverman_factor, is:
(n*(d+2)/4.)**(-1./(d+4)).
or in the case of unequally weighted points:
(neff*(d+2)/4.)**(-1./(d+4)).
Note that this is not the same as "Silverman’s rule of thumb" [6], which
may be more robust in the univariate case; see documentation of the
set_bandwidth method for implementing a custom bandwidth rule.
Good general descriptions of kernel density estimation can be found in [1]
and [2], the mathematics for this multi-dimensional implementation can be
found in [1].
With a set of weighted samples, the effective number of datapoints neff
is defined by:
gaussian_kde does not currently support data that lies in a
lower-dimensional subspace of the space in which it is expressed. For such
data, consider performing principal component analysis / dimensionality
reduction and using gaussian_kde with the transformed data.
B.W. Silverman, "Density Estimation for Statistics and Data
Analysis", Vol. 26, Monographs on Statistics and Applied Probability,
Chapman and Hall, London, 1986.
D.M. Bashtannyk and R.J. Hyndman, "Bandwidth selection for kernel
conditional density estimation", Computational Statistics & Data
Analysis, Vol. 36, pp. 279-298, 2001.