关于NeuralForecast

%load_ext autoreload
%autoreload 2

NeuralForecast 提供了大量以可用性和鲁棒性为重点的神经预测模型。这些模型包括经典网络如 MLPRNN,以及经过验证的新颖贡献,如 NBEATSNHITSTFT 和其他架构。

🎊 特性

  • 外生变量:静态、历史和未来的外生支持。
  • 预测可解释性:绘制趋势、季节性和外生的 NBEATSNHITSTFTESRNN 预测组件。
  • 概率预测:针对分位数损失和参数分布的简单模型适配器。
  • 训练和评估损失:尺度依赖型、百分比和尺度独立错误,以及参数似然。
  • 自动模型选择:并行化的自动超参数调优,有效搜索最佳验证配置。
  • 简单接口:统一的 SKLearn 接口,便于与 StatsForecastMLForecast 兼容。
  • 模型集合:开箱即用的 MLPLSTMRNNTCNDilatedRNNNBEATSNHITSESRNNInformerTFTPatchTSTVanillaTransformerStemGNNHINT 的实现。查看整个集合

为什么?

人们普遍相信神经预测方法能够提高我们流程的准确性和效率。

不幸的是,目前可用的实现和发表的研究尚未充分发挥神经网络的潜力。它们使用起来困难,并且在提高统计方法的表现上持续失败,同时计算成本高。因此,我们创建了NeuralForecast,一个优先考虑经过验证的准确和高效模型,并专注于其可用性的库。

💻 安装

PyPI

您可以通过 Python 包索引 pip 安装 NeuralForecast发布版本

pip install neuralforecast

(建议在 Python 虚拟环境或 Conda 环境中安装。)

Conda

您也可以通过 conda 安装 NeuralForecast发布版本

conda install -c conda-forge neuralforecast

(建议在 Python 虚拟环境或 Conda 环境中安装。)

开发模式

如果您想对代码进行一些修改并实时查看效果(无需重新安装),请按照以下步骤操作:

git clone https://github.com/Nixtla/neuralforecast.git
cd neuralforecast
pip install -e .

如何使用

import numpy as np
import pandas as pd
from IPython.display import display, Markdown

import matplotlib.pyplot as plt
from neuralforecast import NeuralForecast
from neuralforecast.models import NBEATS, NHITS
from neuralforecast.utils import AirPassengersDF

# 拆分数据并声明面板数据集
Y_df = AirPassengersDF
Y_train_df = Y_df[Y_df.ds<='1959-12-31'] # 132次列车
Y_test_df = Y_df[Y_df.ds>'1959-12-31'] # 12项测试

# 使用NBEATS和NHITS模型进行拟合和预测
horizon = len(Y_test_df)
models = [NBEATS(input_size=2 * horizon, h=horizon, max_steps=50),
          NHITS(input_size=2 * horizon, h=horizon, max_steps=50)]
nf = NeuralForecast(models=models, freq='M')
nf.fit(df=Y_train_df)
Y_hat_df = nf.predict().reset_index()

# 情节预测
fig, ax = plt.subplots(1, 1, figsize = (20, 7))
Y_hat_df = Y_test_df.merge(Y_hat_df, how='left', on=['unique_id', 'ds'])
plot_df = pd.concat([Y_train_df, Y_hat_df]).set_index('ds')

plot_df[['y', 'NBEATS', 'NHITS']].plot(ax=ax, linewidth=2)

ax.set_title('AirPassengers Forecast', fontsize=22)
ax.set_ylabel('Monthly Passengers', fontsize=20)
ax.set_xlabel('Timestamp [t]', fontsize=20)
ax.legend(prop={'size': 15})
ax.grid()

🙏 如何引用

如果您享受或受益于使用这些Python实现,引用该仓库将不胜感激。

@misc{olivares2022library_neuralforecast,
    author={Kin G. Olivares 和
            Cristian Challú 和
            Federico Garza 和
            Max Mergenthaler Canseco 和
            Artur Dubrawski},
    title = {{NeuralForecast}: 用户友好的最先进神经预测模型。},
    year={2022},
    howpublished={{PyCon} 盐湖城, 犹他州, 美国 2022},
    url={https://github.com/Nixtla/neuralforecast}
}

Give us a ⭐ on Github