As the title might suggest, my aim is to perform a Time Series Cross Validation using a L1 penalty (Lasso). As the data frame is a time series format, clearly the results of a time series analysis should be more appropriate than a normal cv.
Here are the lines of codes I tried
library(caret)
library(ggplot2)
library(pls)
economics
timeSlices <- createTimeSlices(1:nrow(economics),
initialWindow = 36, horizon = 12, fixedWindow = FALSE)
trainSlices <- timeSlices[[1]]
testSlices <- timeSlices[[2]]
This allows to create two slices for a training set (always getting one more observations) while keeping constant the lenght of the test set. The problem arises here
plsFitTime <- train(unemploy ~ pce + pop + psavert,
data = economics[trainSlices[[1]],],
method = "glmnet",
alpha = 1)
Here the error
Something is wrong; all the RMSE metric values are missing:
RMSE Rsquared MAE
Min. : NA Min. : NA Min. : NA
1st Qu.: NA 1st Qu.: NA 1st Qu.: NA
Median : NA Median : NA Median : NA
Mean :NaN Mean :NaN Mean :NaN
3rd Qu.: NA 3rd Qu.: NA 3rd Qu.: NA
Max. : NA Max. : NA Max. : NA
NA's :9 NA's :9 NA's :9
Error: Stopping
In addition: Warning message:
In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, :
There were missing values in resampled performance measures.
I really don t get what might be wrong with that.
My final objective would be then to perform
pred <- predict(plsFitTime,economics[testSlices[[1]],])
true <- economics$unemploy[testSlices[[1]]]
Any suggestion with that?