知行编程网知行编程网  2022-06-05 14:00 知行编程网 隐藏边栏 |   抢沙发  140 
文章评分 0 次,平均分 0.0

时间序列预测方法总结

来自 | 知乎 作者 | BINGO Hong

链接 | https://zhuanlan.zhihu.com/p/67832773

编辑 | 深度学习这件小事

本文经作者授权转载,仅作学术交流,请勿二次转载

时间序列预测方法总结


1. 时间序列基本规则法-周期因子法


a. 提取时间序列的周期性特征进行预测

参考:时间序列规则法快速入门 https://www.jianshu.com/p/31e20f00c26f?spm=5176.12282029.0.0.36241491UUhnZE

  • 计算周期因子factors

  • 计算base

  • 预测=base*factors


b. 观察序列,当序列存在周期性时,可以用周期因子法做为baseline
  • 在天池竞赛-资金流入流出预测-挑战Baseline-天池大赛-阿里云天池,周期因子可以取得110分+的成绩,排名进500妥妥的。(后面有机会再贴代码)

    挑战baseline比赛链接:https://tianchi.aliyun.com/competition/entrance/231573/introduction?spm=5176.12281949.1003.6.493e24486tbptc


2. 线性回归-利用时间特征做线性回归


a. 提取时间的周期性特点做为特征,此时训练集每条样本为"时间特征->目标值",时间序列的依赖关系被剔除,不需要严格依赖滑窗截取训练样本。常见是将时间用0-1哑变量表达,有以下若干种特征:
  • 将星期转化为了0-1变量,从周一至周天,独热编码共7个变量

  • 将节假日转化为0-1变量,视具体节假日数目,可简单分为两类,"有假日"-"无假日",独热编码共2个变量;或赋予不同编码值,如区分国庆、春节、劳动节等使用1、2、3表示

  • 将月初转化为0-1变量,简单分两类表示为"是月初"-"非月初",共2个特征

  • 类似的月中、月初可以转化为0-1变量

  • 控制时间粒度,区分是weekday or weekend


b. 观察序列,当序列存在周期性时,线性回归也可做为baseline

  • 在天池竞赛-资金流入流出预测-挑战Baseline-天池大赛-阿里云天池,线性回归可以取得100分+的成绩,应该还没到500,多调节下特征就能进去了。


3.传统时序建模方法,ARMA/ARIMA等线性模型。


参考:

  • 写给你的金融时间序列分析:基础篇 

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

  • 自回归/滑动平均阶数判断 Identifying the orders of AR and MA terms in an ARIMA model(https://people.duke.edu/~rnau/411arim3.htm)列举了11条一般原则,其中提到:

    • 差分方法可消除正相关但同时引入负相关

    • AR项可消除正相关,MA项消除负相关

    • AR项和MA项作用会相互抵消,通常包含两种要素时可尝试减少某项,避免过拟合


4.时间序列分解,使用加法模型或乘法模型将原始序列拆分为4部分。


a. 拆分为4部分:长期趋势变动T、季节变动S(显式周期,固定幅度、长度的周期波动)、循环变动C(隐式周期,周期长不具严格规则的波动)和不规则变动I。参考:
  • 时间序列分解法 - MBA智库百科https://wiki.mbalib.com/wiki/时间序列分解法

  • 时间序列分解(https://www.jianshu.com/p/e6d286132690

b. 乘法模型中SCI均为比例,加法模型中SCI与T有相同量纲。
c. 循环变动C较为复杂,短期不体现或归入趋势变化中。

d. 两类平滑方法:

  • 以滑动平均作为平滑方法提取趋势的seasonal_decompose朴素分解。statsmodels.tsa.seasonal.seasonal_decompose(https://www.statsmodels.org/dev/generated/statsmodels.tsa.seasonal.seasonal_decompose.html#statsmodels.tsa.seasonal.seasonal_decompose

  • 以鲁棒局部加权回归作为平滑方法的STL分解。statsmodels.tsa.seasonal.STL

e. 季节性分析。数据中有季节性因素,与整体趋势相比显得比较弱。原文: Investigating Seasonality in a Time Series: A Mystery in Three Parts (https://data.blog/2018/07/24/investigating-seasonality-in-a-time-series-a-mystery-in-three-parts/);中文:干货 | 季节性的分析才不简单,小心不要在随机数据中也分析出季节性

f. 在天池竞赛-资金流入流出预测-挑战Baseline-天池大赛-阿里云天池,时间序列分解方法也能取得很好的成绩。(后面有机会试试这种方法)

  • 【天池大数据赛题解析】资金流入流出预测(附Top4答辩ppt) - 止战 - 博客园(https://www.cnblogs.com/zhizhan/p/4868411.html


5. 特征工程着手,时间滑窗改变数据的组织方式,使用xgboost/LSTM模型/时间卷积网络等。


参考:

  • kaggle商品销量预测1st的思路:特征工程+LGBM/LSTM, 1st place solution | Kaggle (https://www.kaggle.com/c/favorita-grocery-sales-forecasting/discussion/47582

  • kaggle商品销量预测5th的思路:特征工程+LGBM/CNN-DNN/seq2seq,5th Place Solution | Kaggle (https://www.kaggle.com/c/favorita-grocery-sales-forecasting/discussion/47556


6. 转化为监督学习数据集,使用xgboot/LSTM模型/时间卷积网络/seq2seq(attention_based_model)。


参考:

  • 如何用Python将时间序列转换为监督学习问题 - 云+社区 - 腾讯云

    https://cloud.tencent.com/developer/article/1042809

  • Keras中带LSTM的多变量时间序列预测 - 云+社区 - 腾讯云

    https://cloud.tencent.com/developer/article/1041442

  • 时间卷积网络(TCN) 总结:时序模型不再是递归网络(RNN) 的天下,但作为信息粗暴提取的一种方法,请不要神话CNN !

    http://nooverfit.com/wp/时间卷积网络tcn-总结:时序模型不再是递归网络rnn

  • 算法上可以引入注意力机制的seq2seq模型,见过纯粹的seq2seq解法,结合注意力机制的还没见过开源代码(可能是搜索不够仔细)。

  • seq2seq代码:Kaggle-Competition-Favorita/seq2seq

    https://github.com/LenzDu/Kaggle-Competition-Favorita/blob/master/seq2seq.py

  • 注意力机制资料:

    • 台大-李宏毅《Attention_based_model》

    • 他们只说注意力机制(Attention Mechanism)不练,还是我来给大家撸代码讲解(https://juejin.im/post/5bbf41c3f265da0af16160d2#heading-0

    • 《Attention is All You Need》浅读(简介+代码)(https://kexue.fm/archives/4765)

    • 川陀学者:Attention机制详解(二)——Self-Attention与Transformer(https://zhuanlan.zhihu.com/p/47282410

    • The Illustrated Transformer (https://jalammar.github.io/illustrated-transformer/

    • Visualizing A Neural Machine Translation Model (Mechanics of Seq2seq Models With Attention)


7.Facebook-prophet,类似于STL分解思路,因为觉得在控制程度和可解释性上比传统时序模型更有优势,所以单独列车。


参考:
  • 官网说明(英文)

    https://facebook.github.io/prophet/docs/quick_start.html#python-api

  • 官网notbook(英文)

    https://github.com/facebook/prophet/blob/master/notebooks/trend_changepoints.ipynb

  • 中文推荐 @张戎 的文章,从原理到使用都有介绍,很良心。

    张戎:Facebook 时间序列预测算法 Prophet 的研究

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

  • 个人理解,想进一步用好,可以好好看看论文和官网,有空撸遍python的源码

  • 理解prior_scale在代码中如何实现控制趋势项、季节项和节假日项

  • 对于趋势项参数changepoint_range、changepoint_prior_scale如何影响模型拟合和泛化程度

  • 趋势项中的Uncertainty-Intervals(interval_width参数)如何在预测结果使用

  • 论文中的"Simulated Historical Forecasts"对应prophet的Diagnostics工具,可以利用该工具做时间序列的交叉验证评价模型准确程度,如何利用该工具调整模型


8. 深度学习网络,结合CNN+RNN+Attention,作用各不相同互相配合。目前也只是看了论文,有代码的顺便给出代码链接,代码还没细看。


主要设计思想:
  • CNN捕捉短期局部依赖关系

  • RNN捕捉长期宏观依赖关系

  • Attention为重要时间段或变量加权

  • AR捕捉数据尺度变化(没太搞懂啥意思~)


方法:
  • LSTNet:适用于自相关图表现出有明显周期的时间序列,否则与传统方法相当。LSTNet-Pytorch、LSTNet-Keras、LSTNet-Gluon(Mxnet)。

  • TPA-LSTM:改进了attention机制,侧重选择关键变量,而非选择时间步;实验效果说是对周期不明显的时间序列也能有不错效果。TPA-LSTM-Tensorflow


代码的坑填上。
  • LSTNet代码解读, BINGO Hong:LSTNet详解(https://zhuanlan.zhihu.com/p/61795416

  • TPA-LSTM注意力机制, BINGO Hong:TPA注意力机制(TPA-LSTM)

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


9.将时间序列转化为图像,再应用基于卷积神经网络的模型做分析


a. Gramian Angular Field (格拉姆角场GAF)
  • 方法描述:将笛卡尔坐标系下的一维时间序列,转化为极坐标系表示,再使用三角函数生成GAF矩阵。

  • 计算过程:

    • 数值缩放:将笛卡尔坐标系下的时间序列缩放到[0,1]或[-1,1]区间

    • 极坐标转换:使用坐标变换公式,将笛卡尔坐标系序列转化为极坐标系时间序列

    • 角度和/差的三角函数变换:若使用两角和的cos函数则得到GASF,若使用两角差的cos函数则得到GADF

  • 优势:

    • 极坐标中半径表示时间戳,角度表示时间序列数值

    • 通过半径r保持序列的时间依赖性

    • 极坐标保留时间关系的绝对值(翻译得不好,大家可看原文:polar coordinates preserve absolute temporal relations)

    • 每个序列产生唯一的极坐标映射图

    • 可通过GAF矩阵的主对角线,恢复笛卡尔坐标下的原始时间序列

  • 缺点:

    • 当序列长度为n时,产生的GAF矩阵大小为n*n,因此作者建议使用分段聚合近似(Piecewise Aggregation Approximation)保留序列趋势同时减少序列大小。

  • 参考:

    • GAF方法的具体介绍见《Imaging Time-Series to Improve Classification and Imputation》(https://arxiv.org/pdf/1506.00327.pdf

    • GAF的使用工具见pyts.image.GramianAngularField

    • 案例:波动率预测:基于CNN的图像识别策略(附代码) - 云+社区 - 腾讯云(https://cloud.tencent.com/developer/article/1610107


b. Short Time Fourier Transform (短时傅里叶变换STFT)
  • 通用的语音信号处理工具。在我毕业论文里就有使用到,论文还没上知网,链接后面再补吧。

  • 将时间序列转为时频图像。


工具:
  • tslearn:开源的时间序列机器学习python工具包

  • tsfresh:开源的时间序列特征提取python工具包

  • pyts:开源的时间序列分类Python工具包。提供预处理工具及若干种时间序列分类算法


难点:
  • 理解时间序列预测问题是要用历史数据预测未来数据

  • 时间序列问题的训练集、测试集划分

  • 特征工程方法及过程(方法2的过程很有趣)

  • 如何转化为监督学习数据集

  • LSTM计算过程理解,包括输入输出维度、参数数量等

  • seq2seq过程的理解,decoder实现

  • attention注意力机制的原理及实现,包括encoder-decoder attention, self attention, multi-head attention等

  • 时间卷积网络的含义,顾名思义就是将CNN方法用于时间序列中,主要是dilated-convolution and causal-convolution

  • prophet预测原理,各参数对模型拟合效果、泛化效果的影响

  • TPA侧重选择关键变量

  • 时间序列基本规则法中周期因子得计算过程

  • 传统方法如周期因子、线性回归、ARMA等的预测结果表现为,预测趋势大致正确,但对波动预测不理想,体现在波动的幅度差异、相位偏移。

  • 时间序列分解方法。理解加法模型和乘法模型,判断分解模型的选取及分解技巧。


<pre style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><p style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;color: rgb(0, 0, 0);font-family: -apple-system-font, system-ui, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;widows: 1;line-height: 1.75em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;box-sizing: border-box !important;overflow-wrap: break-word !important;">—</span></strong>完<strong style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;box-sizing: border-box !important;overflow-wrap: break-word !important;">—</span></strong></span></strong></span></strong></p><section style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;font-family: -apple-system-font, system-ui, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;widows: 1;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="margin-top: 15px;margin-bottom: 25px;max-width: 100%;opacity: 0.8;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="max-width: 100%;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="margin-top: 15px;margin-bottom: 25px;max-width: 100%;opacity: 0.8;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section><p style="margin-bottom: 15px;padding-right: 0em;padding-left: 0em;max-width: 100%;color: rgb(127, 127, 127);font-size: 12px;font-family: sans-serif;line-height: 25.5938px;letter-spacing: 3px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(0, 0, 0);box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 16px;font-family: 微软雅黑;caret-color: red;box-sizing: border-box !important;overflow-wrap: break-word !important;">为您推荐</span></strong></span></p><p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;">IoU、GIoU、DIoU、CIoU损失函数的那点事儿</p><p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="font-size: 14px;">GitHub重大更新:在线开发上线,是时候卸载IDE了</span></p><p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="color: rgb(87, 107, 149);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;max-width: 100%;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">史上最烂的项目:苦撑12年,600多万行代码...</span></p><p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;">数据分析入门常用的23个牛逼Pandas代码</p><p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;">知乎高赞:985计算机视觉毕业后找不到工作怎么办?<br  /></p></section></section></section></section></section></section></section></section>
时间序列预测方法总结

本篇文章来源于: 深度学习这件小事

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写

发表评论

表情 格式 链接 私密 签到
扫一扫二维码分享