入门
数据要求
数据集输入要求
在此示例中,我们将介绍 core.NeuralForecast 类的数据集输入要求。
core.NeuralForecast 方法作为全局模型运行,接收一组时间序列而不是单个序列。该类使用交叉学习技术来拟合灵活的共享模型,例如神经网络,从而提高了其泛化能力,这在 M4 国际预测竞赛中得到了体现(Smyl 2019,Semenoglou 2021)。
您可以使用 Google Colab 的 GPU 运行这些实验。
长格式
多个时间序列
将您的时间序列存储在 pandas 数据框(dataFrame)中,采用长格式,即每一行代表特定序列和时间戳的观察值。我们来看一个使用 datasetsforecast 库的示例。
Y_df = pd.concat( [series1, series2, ...])
| unique_id | ds | y | |
|---|---|---|---|
| 0 | Y1 | 1975-12-31 | 940.66 | 
| 1 | Y1 | 1976-12-31 | 1084.86 | 
| 20 | Y10 | 1975-12-31 | 2160.04 | 
| 21 | Y10 | 1976-12-31 | 2553.48 | 
| 40 | Y100 | 1975-12-31 | 1424.70 | 
| … | … | … | … | 
| 18260 | Y97 | 1976-12-31 | 1618.91 | 
| 18279 | Y98 | 1975-12-31 | 1164.97 | 
| 18280 | Y98 | 1976-12-31 | 1277.87 | 
| 18299 | Y99 | 1975-12-31 | 1870.00 | 
| 18300 | Y99 | 1976-12-31 | 1307.20 | 
Y_df 是一个数据框(dataFrame),包含三列:unique_id,用于标识每个时间序列的唯一 ID;ds 列,包含时间戳;以及 y 列,包含序列的值。
单个时间序列
如果您只有一个时间序列,则必须包含 unique_id 列。例如,考虑 AirPassengers 数据集。
| timestamp | value | |
|---|---|---|
| 0 | 1949-01-01 | 112 | 
| 1 | 1949-02-01 | 118 | 
| 2 | 1949-03-01 | 132 | 
| 3 | 1949-04-01 | 129 | 
| 4 | 1949-05-01 | 121 | 
| … | … | … | 
| 139 | 1960-08-01 | 606 | 
| 140 | 1960-09-01 | 508 | 
| 141 | 1960-10-01 | 461 | 
| 142 | 1960-11-01 | 390 | 
| 143 | 1960-12-01 | 432 | 
在此示例中,Y_df 只包含两列:timestamp 和 value。要使用 NeuralForecast,我们必须包含 unique_id 列并重命名之前的列。
| unique_id | ds | y | |
|---|---|---|---|
| 0 | 1.0 | 1949-01-01 | 112 | 
| 1 | 1.0 | 1949-02-01 | 118 | 
| 2 | 1.0 | 1949-03-01 | 132 | 
| 3 | 1.0 | 1949-04-01 | 129 | 
| 4 | 1.0 | 1949-05-01 | 121 | 
| … | … | … | … | 
| 139 | 1.0 | 1960-08-01 | 606 | 
| 140 | 1.0 | 1960-09-01 | 508 | 
| 141 | 1.0 | 1960-10-01 | 461 | 
| 142 | 1.0 | 1960-11-01 | 390 | 
| 143 | 1.0 | 1960-12-01 | 432 | 
参考文献
- Slawek Smyl. (2019). “A hybrid method of exponential smoothing and recurrent networks for time series forecasting”. International Journal of Forecasting.
- Artemios-Anargyros Semenoglou, Evangelos Spiliotis, Spyros Makridakis, and Vassilios Assimakopoulos. (2021). Investigating the accuracy of cross-learning time series forecasting methods”. International Journal of Forecasting.

