我一直在研究R中的一个脚本来预测一个数字。
# Load Forecast library
library(forecast)
# Load dataset
bwi <- read.csv(file="C:/Users/nsoria/Downloads/AMS Globales/TEC_BWI.csv", header=TRUE, sep=';', dec=",")
# Create time series starting in January 2015
ts_bwi <- ts(bwi$BWI, frequency = 12, start = c(2015,1))
# Pull out the seasonal, trend, and irregular components from the time series
model <- stl(ts_bwi, s.window = "periodic")
# Predict the next 5 months of SLA
pred <- forecast(model, h = 5)
# Plot the results
plot(pronostico)
这个输出给出了这个
不知何故,预测的行与实际值没有关联。
问题:如何将线路从上次已知值链接到第一个预测值?
编辑01/01:这是CSV所在的link以重现案例。
您需要将实时系列添加到预测的系列中,如下面的代码所示
pred_mod<-pred
ts_real<-pred$x
pred_mod$x<-ts(c(ts_real,pred$mean),frequency=12,start=c(2015,1))
plot(pred_mod)