我正在尝试对4种不同的模型进行交叉验证。目标是预测接下来的10个数据。我的数据集包含180个数据条目。由于某种原因,我的代码未运行。
py <- 171
ny <- 180
sum_squared_errors <- c(model1=0, model2=0, model3=0, model4=0)
for (k in py:ny) {
train_set <- window(log_data1,end=k)
test_set = window(log_data1,start=k,end=k)
forecast1 <- sarima.for(train_set, n.ahead=10, p=1, d=1, q=1)$pred
forecast2 <- sarima.for(train_set, n.ahead=10, p=1, d=2, q=1, P=1, D=1, Q=1, S=6)$pred
forecast3 <- sarima.for(train_set, n.ahead=10, p=2, d=2, q=2, P=1, D=1, Q=1, S=12)$pred
forecast_matrix <- cbind(model1=forecast1,
model2=forecast2,
model3=forecast3)
print(forecast_matrix)
sum_squared_errors <- sum_squared_errors + apply(forecast_matrix, 2, function(col) {
sum((col - test_set)^2)
})
}
print(sum_squared_errors)
print(test_set)
print(train_set)