美文网首页R/Python
神经网络和时间序列

神经网络和时间序列

作者: 茶苯海 | 来源:发表于2018-01-20 11:28 被阅读115次

神经网络可用于给时间序列变量生成预测。
R中的forecast包可用于实现有单层隐藏层的前馈神经网络,并以滞后输入值预测一元时间序列。

使用R中内置数据集Air Passengers
forecast::nnetar函数的用法和参数
获取帮助

library(forecast)
?nnetar
1.用法
nnetar(y, p, P=1, size, repeats=20, xreg=NULL, lambda=NULL, model=NULL,
    subset=NULL, scale.inputs=TRUE, x=y, ...)
2.参数
y    
A numeric vector or time series.  
数值向量或时间序列
p    
Embedding dimension for non-seasonal time series. Number of non-seasonal lags used as inputs. For non-seasonal time series, the default is the optimal number of lags (according to the AIC) for a linear AR(p) model. For seasonal time series, the same method is used but applied to seasonally adjusted data (from an stl decomposition).   
输入非季节性的滞后阶数
P    
Number of seasonal lags used as inputs.   
输入季节性的滞后阶数
size    
Number of nodes in the hidden layer. Default is half of the number of input nodes (including external regressors, if given) plus 1. 
隐藏层节点的个数
repeats 
Number of networks to fit with different random starting weights. These are then averaged when producing forecasts.
以不同随机权重拟合的网络个数
xreg    
Optionally, a vector or matrix of external regressors, which must have the same number of rows as y. Must be numeric.
用于拟合模型的外部回归
lambda  
Box-Cox transformation parameter.
称作box-cox转换参数

建立模型

## 查看下数据
str(AirPassengers)
# fit
fit <- nnetar(AirPassengers,p = 9,P = ,size = 10,repeats = 50,lambda = 0)
# plot
plot(forecast(fit,10))

一个基于神经网络的预测模型生成如下输出结果:

summary(fit)

结果如下:

         Length Class        Mode     
x         144    ts           numeric  
m           1    -none-       numeric  
p           1    -none-       numeric  
P           1    -none-       numeric  
scalex      2    -none-       list     
size        1    -none-       numeric  
lambda      1    -none-       numeric  
subset    144    -none-       numeric  
model      50    nnetarmodels list     
nnetargs    0    -none-       list     
fitted    144    ts           numeric  
residuals 144    ts           numeric  
lags       10    -none-       numeric  
series      1    -none-       character
method      1    -none-       character
call        6    -none-       call     
预测后续的10个区间,图形如下: forecast(fit,10).png

相关文章

  • 神经网络和时间序列

    神经网络可用于给时间序列变量生成预测。R中的forecast包可用于实现有单层隐藏层的前馈神经网络,并以滞后输入值...

  • 一文详解RNN及股票预测实战(Python)!

    循环神经网络(RNN)是基于序列数据(如语言、语音、时间序列)的递归性质而设计的,是一种反馈类型的神经网络,其结构...

  • RNN和LSTM

    循环神经网络——RNN: 循环神经网络的主要用途是处理和预测序列数据,循环神经网络的来源是为了刻画一个序列当前的输...

  • 2018-07-18

    循环神经网络(RNN) 循环神经网络属于前馈神经网络的一个子集,可以接受(时间)序列数据作为输入 A wellkn...

  • 直观理解LSTM(长短时记忆网络)

    长短时神经网络是一种特殊的递归神经网络,所谓递归神经网络就是网络能够解决时间序列问题的预测。所谓递归神经网络就是网...

  • 2020自己动手写循环神经网(1)

    循环神经网络 循环神经网 循环神经网络处理变长的序列,在这点上不同于普通神经网是。在时间序列定义一种递归关系来实现...

  • TensorFlow HOWTO 5.1 循环神经网络(时间序列

    5.1 循环神经网络(时间序列) 循环神经网络(RNN)用于建模带有时间关系的数据。它的架构是这样的。 在最基本的...

  • 学习笔记TF027:卷积神经网络

    卷积神经网络(Convolutional Neural Network,CNN),可以解决图像识别、时间序列信息问...

  • 已写博客目录

    BP神经网络和SVM实现时间序列预测(2019-03-23) 配电网潮流计算(2019-03-23) 用CNN做电...

  • RNN

    RNN RNN 是一种利用神经网络对序列模型的通用模型 利用历史信息结合当前输入进行预测 适合解决时间序列输入输出...

网友评论

    本文标题:神经网络和时间序列

    本文链接:https://www.haomeiwen.com/subject/adzzoxtx.html