#time-series #analysis #forecasting #python-bindings

pyaugurs

为 augurs 时间序列库提供 Python 绑定

2 个版本

0.1.0 2023年9月25日

#11 in #forecasting

MIT/Apache

17KB
280

对 augurs 时间序列框架的 Python 绑定

安装

最终将提供 GitHub 发布的 wheel 包,也许甚至会在 PyPI 上。到那时,安装将变得非常简单

$ pip install augurs

在此之前,需要手动操作。您需要安装 maturin 并拥有该仓库的本地副本。然后,从 crates/pyaugurs 目录,激活您的虚拟环境

$ maturin build --release

您可能还需要 numpy

$ pip install numpy

使用

多季节趋势分解与 LOESS (MSTL) 模型

import augurs as aug
import numpy as np

y = np.array([1.5, 3.0, 2.5, 4.2, 2.7, 1.9, 1.0, 1.2, 0.8])
periods = [3, 4]
# Use an AutoETS trend forecaster
model = aug.MSTL.ets(periods)
model.fit(y)
out_of_sample = model.predict(10, level=0.95)
print(out_of_sample.point())
print(out_of_sample.lower())
in_sample = model.predict_in_sample(level=0.95)

# Or use your own forecaster
class CustomForecaster:
    """See docs for more details on how to implement this."""    
    def fit(self, y: np.ndarray):
        pass
    def predict(self, horizon: int, level: float | None) -> aug.Forecast:
        return aug.Forecast(point=np.array([5.0, 6.0, 7.0]))
    def predict_in_sample(self, level: float | None) -> aug.Forecast:
        return aug.Forecast(point=y)
    ...

model = aug.MSTL.custom_trend(periods, aug.TrendModel(CustomForecaster()))
model.fit(y)
model.predict(10, level=0.95)
model.predict_in_sample(level=0.95)

指数平滑模型

import augurs as aug
import numpy as np

y = np.array([1.5, 3.0, 2.5, 4.2, 2.7, 1.9, 1.0, 1.2, 0.8])
model = aug.AutoETS(3, "ZZN")
model.fit(y)
model.predict(10, level=0.95)

更多即将到来!

依赖项

约 10-16MB
约 221K SLoC