gloonts是一个用于概率时间序列建模的python工具包,围绕mxnet构建。
gluonts的Python项目详细描述
gloonts-python中的概率时间序列建模
Glunts是一个用于概率时间序列建模的Python工具包, 围绕Apache MXNet (incubating)构建。
GluOnts提供了在时间序列数据集上加载和迭代的实用程序, 准备好接受培训的最先进的模型,以及定义 你自己的模型和快速试验不同的解决方案。
安装
GluOnts需要Python3.6,而且最简单
安装方法是通过pip
:
pip install gluonts
快速入门指南
这个简单的例子演示了如何在一些数据上从GluOnts训练模型, 然后用它来做预测。作为第一步,我们需要收集 一些数据:在这个例子中,我们将使用提到 AMZN股票代码。
importpandasaspdurl="https://raw.githubusercontent.com/numenta/NAB/master/data/realTweets/Twitter_volume_AMZN.csv"df=pd.read_csv(url,header=0,index_col=0)
前100个数据点如下:
importmatplotlib.pyplotaspltdf[:100].plot(linewidth=2)plt.grid(which='both')plt.show()
我们现在可以为模型准备一个训练数据集。
GluOnts中的数据集本质上是
字典:每个字典代表一个时间序列
可能有关联的特征。在这个例子中,我们只有一个
项,由"start"
字段指定,该字段是
第一个数据点和包含时间序列数据的"target"
字段。
对于培训,我们将使用截至2015年4月5日午夜的数据。
fromgluonts.dataset.commonimportListDatasettraining_data=ListDataset([{"start":df.index[0],"target":df.value[:"2015-04-05 00:00:00"]}],freq="5min")
gloonts中的预测模型是一个predictor对象。一种获得
预测器是通过训练对应的estimator来实现的。实例化
估计器需要指定它将
处理,以及要预测的时间步数。在我们的例子中
我们用了5分钟的数据,所以freq="5min"
,
我们将训练一个模型来预测下一个小时,所以prediction_length=12
。
我们还指定了一些最小的训练选项。
fromgluonts.model.deeparimportDeepAREstimatorfromgluonts.trainerimportTrainerestimator=DeepAREstimator(freq="5min",prediction_length=12,trainer=Trainer(epochs=10))predictor=estimator.train(training_data=training_data)
在培训期间,将显示有关进度的有用信息。
要全面了解可用选项,请参阅
关于DeepAREstimator
(或其他估计器)和Trainer
的文档。
我们现在准备好做预测了:我们将在接下来的一个小时内进行预测 2015年4月15日午夜。
test_data=ListDataset([{"start":df.index[0],"target":df.value[:"2015-04-15 00:00:00"]}],freq="5min")fromgluonts.dataset.utilimportto_pandasfortest_entry,forecastinzip(test_data,predictor.predict(test_data)):to_pandas(test_entry)[-60:].plot(linewidth=2)forecast.plot(color='g',prediction_intervals=[50.0,90.0])plt.grid(which='both')
请注意,预测是按概率分布显示的: 阴影区域分别代表50%和90%的预测区间, 以中间带为中心(深绿色线)。
更多示例
以下是了解如何使用 胶子的许多特性:
- Quick Start Tutorial:快速入门指南。
- Extended Forecasting Tutorial:关于预测的详细教程。
- evaluate_model.py:如何训练模型和计算评估指标。
- benchmark_m4.py:如何评估和比较多个数据集上的多个模型。
以下模块说明如何实现自定义模型:
贡献
如果你想为这个项目做贡献,请参考我们的 contribution guidelines。
引用
如果您在科学出版物中使用gloonts,我们建议您添加 以下对关联的 paper:
@article{gluonts,
title={{GluonTS: Probabilistic Time Series Modeling in Python}},
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.},
journal={arXiv preprint arXiv:1906.05264},
year={2019}
}