Weighted Gaussian kernel density estimation in `python`

前端 未结 3 1973
野的像风
野的像风 2020-12-14 21:32

Update: Weighted samples are now supported by scipy.stats.gaussian_kde. See here and here for details.

It is currently not possible to u

3条回答
  •  萌比男神i
    2020-12-14 21:51

    For univariate distributions you can use KDEUnivariate from statsmodels. It is not well documented, but the fit methods accepts a weights argument. Then you cannot use FFT. Here is an example:

    import matplotlib.pyplot as plt
    from statsmodels.nonparametric.kde import KDEUnivariate
    
    kde1= KDEUnivariate(np.array([10.,10.,10.,5.]))
    kde1.fit(bw=0.5)
    plt.plot(kde1.support, [kde1.evaluate(xi) for xi in kde1.support],'x-')
    
    kde1= KDEUnivariate(np.array([10.,5.]))
    kde1.fit(weights=np.array([3.,1.]), 
             bw=0.5,
             fft=False)
    plt.plot(kde1.support, [kde1.evaluate(xi) for xi in kde1.support], 'o-')
    

    which produces this figure:

提交回复
热议问题