时间序列预测的交叉验证

如何解决时间序列预测的交叉验证

给定比利时电力系统 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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?