pol*_*ian 2 python kernel-density scikit-learn
这个想法是在沿 1D 散布的每个点上方堆叠一个内核。具体来说,内核的峰值与每个点的 x 轴点对齐/居中。这类似于 内核密度估计,除了如下图所示,每个点仅堆叠一半内核。
最终,将计算每个密度的总和,并将产生一条曲线(即灰线),如下所示。
作为起点,我挖掘了scikit学习模块的核密度估计以获得一个想法。但是,我没有找到任何关于它们在每个点顶部内核的堆栈的方式/位置的任何行。
如果有人可以为我提供很好的阅读材料以实现这一目标,我真的很感激。
这是你想要的吗?对不起,图表没有你的一半漂亮,但我认为这不是重点
import numpy as np
from scipy.stats import norm
# define a half-kernel function. We normalize to have integral(half_kernel) = 1 if required
def half_kernel(x, center, width = 1, normalize = True):
kernel = (x>=center)*norm.pdf(x, center, width)
if normalize:
kernel *= 2
return kernel
# this are the points where we center our kernels -- random for testing
centers = np.random.normal(0.0,2.0,7)
# Grid on which we look at the results
x = np.linspace(-3.0,3.0,101)
# get the results here, each column is one of the kernels
discr_kernels = np.zeros((len(x),len(centers)))
for n in range(len(centers)):
discr_kernels[:,n] = half_kernel(x, centers[n])
y = discr_kernels.sum(axis= 1)
plt.plot(x,discr_kernels,'--')
plt.plot(x,y, '.-', label = 'total')
plt.legend(loc = 'best')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
151 次 |
| 最近记录: |