[英]Gaussian kernel density smoothing for pandas.DataFrame.resample?
I am using pandas.DataFrame.resample
to resample random events to 1 hour intervals and am seeing very stochastic results that don't seem to go away if I increase the interval to 2 or 4 hours.我正在使用
pandas.DataFrame.resample
将随机事件重新采样到 1 小时的间隔,并且看到非常随机的结果,如果我将间隔增加到 2 或 4 小时,这些结果似乎不会消失。 It makes me wonder whether Pandas has any type of method for generating a smoothed density kernel like a Gaussian kernel density method with an adjustable bandwidth to control smoothing.这让我想知道 Pandas 是否有任何类型的方法来生成平滑的密度内核,如具有可调带宽的高斯内核密度方法来控制平滑。 I'm not seeing anything in the documentation, but thought I would post here before posting on the developer list server since that is their preference.
我没有在文档中看到任何内容,但我想我会在发布到开发人员列表服务器之前先在这里发布,因为这是他们的偏好。 Scikit-Learn has precisely the Gaussian kernel density function that I want , so I will try to make use of it, but it would be a fantastic addition to Pandas.
Scikit-Learn恰好具有我想要的高斯核密度函数,因此我将尝试使用它,但这将是对 Pandas 的绝佳补充。
Any help is greatly appreciated!任何帮助是极大的赞赏!
hourly[0][344:468].plot()
Pandas has the ability to apply an aggregation over a rolling window. Pandas 能够在滚动窗口上应用聚合。 The
win_type
parameter controls the window's shape. win_type
参数控制窗口的形状。 The center
parameter can be set in order for the labels to be set at the center of the window, instead of the right edge.可以设置
center
参数,以便将标签设置在窗口的中心,而不是右边缘。 To do Gaussian smoothing:做高斯平滑:
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 http://pandas.pydata.org/pandas-docs/stable/computation.html#rolling
I have now found that this is option is available in pandas.stats.moments.ewma
and it works quite nicely.我现在发现这个选项在
pandas.stats.moments.ewma
可用,而且效果很好。 Here are the results:结果如下:
from pandas.stats.moments import ewma
hourly[0][344:468].plot(style='b')
ewma(hourly[0][344:468], span=35).plot(style='k')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.