Weighted Gaussian kernel density estimate in `python`

It is currently not possible to use scipy.stats.gaussian_kde to estimate the density of a random variable based on weighted samples . What methods are available for estimating the density of continuous random variables based on weighted samples?

+6
source share
2 answers

Neither sklearn.neighbors.KernelDensity nor statsmodels.nonparametric seems to support weighted samples. I modified scipy.stats.gaussian_kde to provide heterogeneous sample weights and thought that the results might be useful to others. An example is shown below.

example

You can find the ipython laptop ipython : http://nbviewer.ipython.org/gist/tillahoffmann/f844bce2ec264c1c8cb5

Implementation Details

Weighted average arithmetic mean

weighted arithmetic mean

the covariance matrix of unbiased data is then determined unbiased covariance matrix

Bandwidth can be selected by scott or silverman rules, as in scipy . However, the number of samples used to calculate the bandwidth, Kish approximation for the effective sample size .

+15
source

Check out the PyQT-Fit packages and statistics for Python. It seems that they have a kernel density estimate with weighted observations.

0
source

Source: https://habr.com/ru/post/980087/


All Articles