python - How does the stats.gaussian_kde method calcute the pdf? -


i using scipy.stats.gaussian_kde method scipy generate random samples data.

it works fine! have found out method has inbuilt functions calculate probability density function of given set of points (my data).

i know how calculates pdf provided set of points.

here small example:

import numpy np import scipy.stats scipy import stats  def getdistribution1(data):     kernel = stats.gaussian_kde(data,bw_method=0.06)     class rv(stats.rv_continuous):         def _rvs(self, *x, **y):             return kernel.resample(int(self._size)) #random variates         def _cdf(self, x):             return kernel.integrate_box_1d(0,max(x)) #integrate pdf between 2 bounds (-inf x here!)         def _pdf(self, x):             return kernel.evaluate(x)  #evaluate estimated pdf on provided set of points     return rv(name='kdedist')  test_data = np.random.random(100) # random test data  distribution_data = getdistribution1(test_data) pdf_data = distribution_data.pdf(test_data) # pdf of data 

in above piece of code, there exists 3 methods,

  1. rvs generate random samples based on data
  2. cdf integral of pdf 0 max(data)
  3. pdf pdf of data

the reason need pdf because i trying calculate weights data based on probability. so can give each of data point probability can use weights.

i know here how should proceed calculate weights?

p.s. forgive me asking same question in cross validated, there seems no response!

the online docs have link source code, gaussian_kde here: https://github.com/scipy/scipy/blob/v0.15.1/scipy/stats/kde.py#l193


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -