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
NeuralProphet模型集成了Prophet的所有优点,不仅具有不错的可解释性,还有优于Prophet的预测性能。
pip install neuralprophet
导入包:
from neuralprophet import NeuralProphet
调用:
m = NeuralProphet()
metrics = m.fit(df)
forecast = m.predict(df)
可视化结果:
fig_forecast = m.plot(forecast)
fig_components = m.plot_components(forecast)
fig_model = m.plot_parameters()
预测:
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)
| 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_lags>0时,建议取值大于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 |