[英]Time series prediction via ARIMA model
嗨,我是时间序列领域的新手。 我想对给定的时间序列进行预测
我使用下面的代码:
library(forecast)
library(TSPred)
dataSet <- 'data'
dataSetPath <- paste0("data/", dataSet, '.csv')
# load data
recDF <- read.csv(dataSetPath, skip=0)
rt = ts(recDF["s2"])
if(dataSet=="data"){
nTrain <- 3000
nSkip <- nTrain
nData <- length(rt)
testLength <- nData - nSkip
# testLength
arima_output90 = vector(mode="numeric", length=testLength)
real = vector(mode="numeric", length=testLength)
pred2 <- arimapred(rt[seq(1, nTrain)], n.ahead=testLength)
forecast::auto.arima(rt[seq(1, nTrain)])
# Brute force ARIMA - recompute model every step
# while making predictions for the next N hours.
for(i in nSkip+1:testLength)
{
# Compute ARIMA on the full dataset up to this point
trainSet = window(rt, start=i-nTrain, end=i)
fit_arima <- forecast::auto.arima(trainSet)
# fcast_arima <- predict(fit_arima, n.ahead = 5, se.fit = TRUE)
# mean <- fcast_arima$pred
# std <- fcast_arima$se
fcast_arima <- forecast(fit_arima, h=50)
pred <- fcast_arima$mean
arima_output50[i] = pred[50]
real[i] = rt[i]
cat("step: ",i ,"true : ", rt[i], " prediction: ", pred[50], '\n')
}
我想在同一图中绘制预测值和真实值的图形,以便在相同时间步长下可视化真实值和预测值。 这怎么办?
在上面的模型中,在时间步长t中,预测pred [50]是否参考值rt [i + 50](我想提前50个时间步长预测),还是参考rt [i](根据之前训练过的模型蛮力估计值)?
其中,i是代码中的当前时间步,而rt是时间步i的实际值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.