GluonTS - Python 中的概率时间序列建模#

PyPI GitHub Static Static PyPI Downloads

📢 重磅新闻: 我们发布了 Chronos,这是一套用于零样本时间序列预测的预训练模型。Chronos 可以为训练期间未见的新时间序列生成准确的概率预测。在此查看 这里

GluonTS 是一个用于概率时间序列建模的 Python 包,专注于基于 PyTorchMXNet 的深度学习模型。

安装#

GluonTS 需要 Python 3.7 或更高版本,最简单的安装方法是使用 pip

# install with support for torch models
pip install "gluonts[torch]"

# install with support for mxnet models
pip install "gluonts[mxnet]"

有关 GluonTS 如何安装的更多信息,请参阅文档

简单示例#

为了说明如何使用 GluonTS,我们使用 airpassengers 数据集训练一个 DeepAR 模型并进行预测。该数据集包含一个介于 1949 年至 1960 年间的月度乘客数量时间序列。我们在前九年数据上训练模型,并对剩余三年进行预测。

import pandas as pd
import matplotlib.pyplot as plt

from gluonts.dataset.pandas import PandasDataset
from gluonts.dataset.split import split
from gluonts.torch import DeepAREstimator

# Load data from a CSV file into a PandasDataset
df = pd.read_csv(
    "https://raw.githubusercontent.com/AileenNielsen/"
    "TimeSeriesAnalysisWithPython/master/data/AirPassengers.csv",
    index_col=0,
    parse_dates=True,
)
dataset = PandasDataset(df, target="#Passengers")

# Split the data for training and testing
training_data, test_gen = split(dataset, offset=-36)
test_data = test_gen.generate_instances(prediction_length=12, windows=3)

# Train the model and make predictions
model = DeepAREstimator(
    prediction_length=12, freq="M", trainer_kwargs={"max_epochs": 5}
).train(training_data)

forecasts = list(model.predict(test_data.input))

# Plot predictions
plt.plot(df["1954":], color="black")
for forecast in forecasts:
  forecast.plot()
plt.legend(["True values"], loc="upper left", fontsize="xx-large")
plt.show()
[train-test]

请注意,预测结果以概率分布的形式显示,阴影区域表示 50% 和 90% 的预测区间。

贡献#

如果您希望为本项目做出贡献,请参阅我们的贡献指南

引用#

如果您在科学出版物中使用 GluonTS,除了与您的工作相关的任何特定模型引用外,我们鼓励您添加以下相关论文的引用

@article{gluonts_jmlr,
  author  = {Alexander Alexandrov and Konstantinos Benidis and Michael Bohlke-Schneider
    and Valentin Flunkert and Jan Gasthaus and Tim Januschowski and Danielle C. Maddix
    and Syama Rangapuram and David Salinas and Jasper Schulz and Lorenzo Stella and
    Ali Caner Türkmen and Yuyang Wang},
  title   = {{GluonTS: Probabilistic and Neural Time Series Modeling in Python}},
  journal = {Journal of Machine Learning Research},
  year    = {2020},
  volume  = {21},
  number  = {116},
  pages   = {1-6},
  url     = {http://jmlr.org/papers/v21/19-820.html}
}
@article{gluonts_arxiv,
  author  = {Alexandrov, A. and Benidis, K. and Bohlke-Schneider, M. and
    Flunkert, V. and Gasthaus, J. and Januschowski, T. and Maddix, D. C.
    and Rangapuram, S. and Salinas, D. and Schulz, J. and Stella, L. and
    Türkmen, A. C. and Wang, Y.},
  title   = {{GluonTS: Probabilistic Time Series Modeling in Python}},
  journal = {arXiv preprint arXiv:1906.05264},
  year    = {2019}
}