🎊 特性

  • 外部变量:支持静态、历史和未来外部变量。
  • 预测可解释性:绘制趋势、季节性和外部 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 logging

import pandas as pd
from utilsforecast.plotting import plot_series

from neuralforecast import NeuralForecast
from neuralforecast.models import NBEATS, NHITS
from neuralforecast.utils import AirPassengersDF
logging.getLogger('pytorch_lightning').setLevel(logging.ERROR)
# Split data and declare panel dataset
Y_df = AirPassengersDF
Y_train_df = Y_df[Y_df.ds<='1959-12-31'] # 132 train
Y_test_df = Y_df[Y_df.ds>'1959-12-31'] # 12 test

# Fit and predict with NBEATS and NHITS models
horizon = len(Y_test_df)
models = [NBEATS(input_size=2 * horizon, h=horizon, max_steps=100, enable_progress_bar=False),
          NHITS(input_size=2 * horizon, h=horizon, max_steps=100, enable_progress_bar=False)]
nf = NeuralForecast(models=models, freq='ME')
nf.fit(df=Y_train_df)
Y_hat_df = nf.predict()

# Plot predictions
plot_series(Y_train_df, Y_hat_df)
Seed set to 1
Seed set to 1

🙏 如何引用

如果您喜欢使用或从这些 Python 实现中受益,非常感谢引用本代码库。

@misc{olivares2022library_neuralforecast,
    author={Kin G. Olivares and
            Cristian Challú and
            Federico Garza and
            Max Mergenthaler Canseco and
            Artur Dubrawski},
    title = {{NeuralForecast}: User friendly state-of-the-art neural forecasting models.},
    year={2022},
    howpublished={{PyCon} Salt Lake City, Utah, US 2022},
    url={https://github.com/Nixtla/neuralforecast}
}