在R中使用神经网络进行时间序列预测的示例 [英] Example of Time Series Prediction using Neural Networks in R

查看:1104
本文介绍了在R中使用神经网络进行时间序列预测的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都有一个简短的简短教育示例,该如何使用神经网络(R中的 nnet )进行预测? 这是一个时间序列示例,在R中

Anyone's got a quick short educational example how to use Neural Networks (nnet in R) for the purpose of prediction? Here is an example, in R, of a time series

T = seq(0,20,length=200)
Y = 1 + 3*cos(4*T+2) +.2*T^2 + rnorm(200)
plot(T,Y,type="l")

非常感谢

大卫

推荐答案

我认为您可以使用caret包,特别是train函数

I think you can use the caret package and specially the train function

This function sets up a grid of tuning parameters for a number 
      of classification and regression routines.

require(quantmod) 
require(nnet)
require(caret)
T = seq(0,20,length=200)
y = 1 + 3*cos(4*T+2) +.2*T^2 + rnorm(200)
dat <- data.frame( y, x1=Lag(y,1), x2=Lag(y,2))
names(dat) <- c('y','x1','x2')
dat <- dat[c(3:200),] #delete first 2 observations
#Fit model
model <- train(y ~ x1+x2 , 
               dat, 
               method='nnet', 
               linout=TRUE, 
               trace = FALSE)
ps <- predict(model, dat)

#Examine results

plot(T,Y,type="l",col = 2)
lines(T[-c(1:2)],ps, col=3)
legend(5, 70, c("y", "pred"), cex=1.5, fill=2:3)

这篇关于在R中使用神经网络进行时间序列预测的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆