2014-11-24 112 views
3

我使用pandas.DataFrame.resample将随机事件重新采样到1小时的间隔,并且看到非常随机的结果,如果我将间隔增加到2或4小时,结果似乎不会消失。这让我怀疑Pandas是否有任何类型的方法来生成平滑密度内核,如带有可调整带宽的高斯核密度方法来控制平滑。我在文档中没有看到任何内容,但是我认为在张贴在开发人员列表服务器上之前,我会在这里发帖,因为这是他们的偏好。 Scikit-Learn有precisely the Gaussian kernel density function that I want,所以我会尽量利用它,但这对熊猫来说是一个很棒的补充。pandas.DataFrame.resample的高斯核密度平滑?

任何帮助,非常感谢!

hourly[0][344:468].plot() 

enter image description here

回答

2

我现在已经找到了,这是选项在pandas.stats.moments.ewma和它的作品相当不错。下面是结果:

from pandas.stats.moments import ewma 

hourly[0][344:468].plot(style='b') 
ewma(hourly[0][344:468], span=35).plot(style='k') 

enter image description here

+2

指数加权移动平均是实时(仅向后看)滤波器,并且是不一样的高斯核,这是假想时间(期待和落后)。 – kb0 2017-05-18 20:09:26

3

大熊猫拥有一个滚动窗口申请一个聚集的能力。​​参数控制窗口的形状。可以设置参数center,以便将标签设置在窗口的中心而不是右边缘。做高斯平滑:

hrly = pd.Series(hourly[0][344:468]) 
smooth = hrly.rolling(window=5, win_type='gaussian', center=True).mean(std=0.5) 

http://pandas.pydata.org/pandas-docs/stable/computation.html#rolling