0

I am trying to do hyperparameter tuning for Lasso and Elastic Net using R caret's train function. I want to have horizon=1 to validate each fold with only one validation datapoint.

myTimeControl <- trainControl(method = "timeslice",
                                  initialWindow = 20,
                                  horizon = 1,
                                  savePredictions = "final",
                                  fixedWindow = FALSE,
                                  allowParallel = TRUE)
# Lasso
fraction <- seq(0, 1, by = 0.1)
lassoGrid <-  expand.grid(fraction=fraction)
lasso <- caret::train(y1 ~ ., data = df_lagged,
                              trControl = myTimeControl, metric = 'RMSE',
                              method = 'lasso', tuneGrid = lassoGrid,
                              preProcess = c("center", "scale"))
 
# Elastic Net
enetGrid <-  expand.grid(fraction=fraction,
                                 lambda=c(0.01, 0.025, 0.05, 0.1, 0.2, 0.5))
 enet <- caret::train(y1 ~ ., data = df_lagged,
                             trControl = myTimeControl, metric = 'RMSE',
                             method = 'enet', tuneGrid = enetGrid,
                             preProcess = c("center", "scale"))

However, I am unable to do so and get the following warning instead:

Error in { : 
  task 1 failed - "arguments imply differing number of rows: 11, 2"

I didn't receive this error when horizon is more than 1.

Any advice on why this is happening? Thanks in advance!

This issue only arises when horizon=1. All other values of horizon works just fine.

0 Answers0