如何解决时间序列预测的交叉验证
给定比利时电力系统 2010-01-04 至 2016-10-30 期间限价的小时时间序列。
我的数据有以下信息:
datetime_utc:记录日期和时间 Generation_BE:比利时计划发电 Generation_FR:法国计划发电 Prices.BE:比利时假期 OTS 电力BE:比利时国定假日(1 如果是,0 如果不是)
>训练数据:
> dput(head(data1))
structure(list(datetime_utc = c("2010-01-04 00:00:00","2010-01-04 01:00:00","2010-01-04 02:00:00","2010-01-04 03:00:00","2010-01-04 04:00:00","2010-01-04 05:00:00"),Generation_BE = c(13143.7,13143.7,13143.7),Generation_FR = c(63599,62212,62918,62613,62432,63411),Prices.BE = c(37.15,33.47,28,21.29,16.92,28),holidaysBE = c(0L,0L,0L)),row.names = c(NA,6L),class = "data.frame")
测试数据:
> dput(head(data2))
structure(list(datetime_utc = c("2016-10-24 00:00:00","2016-10-24 01:00:00","2016-10-24 02:00:00","2016-10-24 03:00:00","2016-10-24 04:00:00","2016-10-24 05:00:00"),Generation_BE = c(9615.7075,9626.865,9648.0025,9668.42,9681.805,9688.425),Generation_FR = c(45605L,44629L,44073L,44359L,44056L,44799L),Prices.BE = c(44.6,40.92,37.39,36.4,33.01,37.89),class = "data.frame")
我已经为 Prices.BE 时间序列构建了时间序列交叉验证,我想预测 Prices.BE 7 天的时间段,因此对于 168 次观察,因为我们有每小时数据。
代码:
> k <- 168
> n <- length(data1)
> mae1 <- mae2 <- matrix(NA,n-k,12)
Error in matrix(NA,n - k,12) : invalid 'nrow' value (< 0)
> st <- tsp(data1)[1]+(k-2)/12
>
> for(i in 1:(n-k))
+ {
+ xshort <- window(data1,end=st + i/12)
+ xnext <- window(data1,start=st + (i+1)/12,end=st + (i+12)/12)
+ fit1 <- Arima(xshort,order=c(3,1),seasonal=list(order=c(0,1,period=12),+ include.drift=TRUE,lambda=0,method="ML")
+ fcast1 <- forecast(fit1,h=12)
+ fit2 <- ets(xshort,model="MMM",damped=TRUE)
+ fcast2 <- forecast(fit2,h=12)
+ mae1[i,1:length(xnext)] <- abs(fcast1[['mean']]-xnext)
+ mae2[i,1:length(xnext)] <- abs(fcast2[['mean']]-xnext)
+ }
Error in attr(x,"tsp") <- c(1,NROW(x),1) :
invalid time series parameters specified
>
> plot(1:12,colMeans(mae1,na.rm=TRUE),type="l",col=2,xlab="horizon",ylab="MAE",+ ylim=c(0.65,1.05))
Error in h(simpleError(msg,call)) :
error in evaluating the argument 'y' in selecting a method for function 'plot': object 'mae1' not found
> lines(1:12,colMeans(mae2,col=3)
> legend("topleft",legend=c("ARIMA","ETS"),col=2:3,lty=1)
正如您所看到的代码显示了一些错误,我无法找到有关它们的解决方案,欢迎任何帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。