Fork me on GitHub

Python系列文章-NeuralProphet时间序列预测包使用

目录

  • 背景

  • 第一部分 第一个项目

  • 第二部分 总结

  • 参考文献及资料

背景

NeuralProphet之一:安装与使用

论文PDF: NeuralProphet: Explainable Forecasting at Scale 文档地址:https://neuralprophet.com/html/contents.html
数据地址:https://github.com/ourownstory/neuralprophet-data
示例地址:https://github.com/ourownstory/neural_prophet/tree/main/tutorials

1 概述
NeuralProphet模型集成了Prophet的所有优点,不仅具有不错的可解释性,还有优于Prophet的预测性能。

使用PyTorch作为后端进行优化的梯度下降法。
使用AR-Net对时间序列的自相关进行建模。
使用seepearate前馈神经网络对滞后回归者进行建模。
可配置的FFNNs非线性深层。
可调整到特定的预测范围(大于1)。
自定义损失和指标。
2 安装
pip install neuralprophet
1.
3 使用
导入包:

from neuralprophet import
1.
调用:

m = NeuralProphet()
metrics = m.fit(df)
forecast = m.predict(df)
1.
2.
3.
可视化结果:

fig_forecast = m.plot(forecast)
fig_components = m.plot_components(forecast)
fig_model = m.plot_parameters()
1.
2.
3.
预测:

m = NeuralProphet().fit(df, freq=”D”)
df_future = m.make_future_dataframe(df, periods=30)
forecast = m.predict(df_future)
fig_forecast = m.plot(forecast)

超参数

https://blog.51cto.com/shanglianlm/5605590

https://zhuanlan.zhihu.com/p/333210630

Parameter Default Value 说明 备注
growth linear
changepoints None 手动设置改变点
n_changepoints 5 控制趋势灵活度
changepoints_range 0.8 默认值0.8,表示后20%的训练数据无changepoints
trend_reg 0 趋势正则项
trend_reg_threshold False
yearly_seasonality auto 默认6
weekly_seasonality auto 默认 4
daily_seasonality auto 默认6
seasonality_mode additive additive,multiplicative
seasonality_reg 0 值越大正则约束越大 0.1-1或者1-100
n_forecasts 1 预测范围,1意味着将来预测一步
n_lags 0 定义是否使用AR-Net,n_lags决定AR-Net回看步数,建议取值大于n_forecasts
num_hidden_layers 0 定义FFNNs的隐藏层数,0意味着只有一个隐藏层 0,1,2
d_hidden None 隐藏层的单元数,如果未指定,默认为n_lags + n_forecasts n_lags 和 n_forecasts 之间
ar_sparsity None 0完全稀疏,1无正则约束 0-1
learning_rate None 如果未指定,自动调整
epochs None 如果未指定,根据数据大小设定
batch_size None
loss_func Huber 如果未指定,根据数据大小设定 Huber, MSE,torch.nn.modules.loss
optimizer AdamW AdamW,SDG
train_speed None
normalize auto min-max normalization
impute_missing True 惩罚缺失值
collect_metrics True 默认计算mae 和 rmse

参考文献及资料

1、官网介绍:https://github.com/ourownstory/neural_prophet

https://github.com/ourownstory/neural_prophet/tree/main/tutorials

0%