Kernel density estimation
A common task in statistics is to estimate the probability density function
(PDF) of a random variable from a set of data samples. This task is called
density estimation. The most well-known tool to do this is the histogram.
A histogram is a useful tool for visualization (mainly because everyone
understands it), but doesn’t use the available data very efficiently. Kernel
density estimation (KDE) is a more efficient tool for the same task. The
scipy.stats.gaussian_kde estimator can be used to estimate the PDF of
univariate as well as multivariate data. It works best if the data is unimodal.
Univariate estimation
We start with a minimal amount of data in order to see how
scipy.stats.gaussian_kde works and what the different options for
bandwidth selection do. The data sampled from the PDF are shown as blue dashes
at the bottom of the figure (this is called a rug plot):