Caret和Caret合奏用于时间序列交叉验证

时间:2019-03-19 19:19:17

标签: r time-series cross-validation r-caret

我正在尝试使用Time Series Cross Validation来使用caret和caretEnsemble评估和堆叠学习算法。插入符通过method =“ timeslice”直接支持此操作-但是,插入符合奏不

  

caretList当前不知道如何处理交叉验证method ='timeslice'。请手动指定trControl $ index

似乎可以使用

手动创建索引
  

createTimeSlices

但是,这在下面的最小工作示例中会产生以下错误

  

错误:正在停止   另外:警告消息:   在nominalTrainWorkflow(x = x,y = y,wts =重量,info = trainInfo,:     重新采样的绩效指标中缺少值。

library(tidyverse)
library(caret)
library(caretEnsemble)

dfml=data.frame(date=seq(as.Date("2014/09/04"), by = "day", length.out = 1090),y=rnorm(1090),x=rnorm(1090))
index=createTimeSlices(dfml$y,365,horizon = 1,fixedWindow = TRUE)

n=726
seeds <- vector(mode = "list", length = n) # creates an empty vector containing lists
for(i in 1:(n-1)){seeds[[i]] <- sample.int(1000, 3) }
seeds[[n]] <- sample.int(1000, 1)

myIndexControl <- trainControl(method = "cv",
                               allowParallel = TRUE,
                               seeds = seeds,index=index$train,indexOut=index$test)
alg_list <- c("glmnet", "gbm", "lm")
multi_mod <- caretList(y ~ . , 
                       data = dfml, 
                       trControl = myIndexControl, 
                       methodList = alg_list,
                       family="gaussian",
                       metric = "RMSE", seeds=seeds)

任何建议或解决方法将不胜感激。 可以通过这种方式调整单个模型

glmnet.fit =train( y~ .,
               data = df,
               method = "glmnet",
               verbose=FALSE, trControl = myIndexControl,seeds=seeds,tuneLength.num=2,linout = TRUE)

0 个答案:

没有答案