import pandas as pd
def kz(series, window, iterations):
"""KZ filter implementation
series is a pandas series
window is the filter window m in the units of the data (m = 2q+1)
iterations is the number of times the moving average is evaluated
"""
z = series.copy()
for i in range(iterations):
z = pd.rolling_mean(z, window=window, min_periods=1, center=True)
return z
我刚调查过同样的问题。在pandas中,实际的KZ过滤器非常简单:
据我所知,不容易实现的是Kologorov Zurbenko过滤器(KZA)的自适应版本。这至少需要一种滚动平均法,该方法允许在中心左右两侧指定不同的窗口长度。位于https://cran.r-project.org/web/packages/kza/index.html的C代码看起来相当简单和直接,但它需要循环,因此如果直接用Python实现的话,速度会非常慢。在
相关问题 更多 >
编程相关推荐