# glmnet foldid for time series data

I'm currently working with cv.glmnet and it is my understanding that you should not use normal cross validation for time series data. Is it possible to use the foldid argument with cv.glmnet in order to accomplish cross validation with time series data?

No, it won't be reasonable to use cv.glmnet for cross validation on time series data. A good explanation how CV should look like on time series data can be found here:

https://robjhyndman.com/hyndsight/tscv/

In short, a standard CV would skip time points randomly and thus destroy the temporal relationships you want to identify. (I assume that your samples are your time points, since you didn't give details on your data.)

They recommend to use the forecast package in R. Unfortunately, I don't know of a LASSO implementation of cross validation for time series data.

• Note that forecast is now deprecated in favour of the tidyverts family of packages – Hong Ooi Feb 14 '20 at 11:29

For time series cross validation, you can use caret library in R.

See the following for further reference.

https://topepo.github.io/caret/data-splitting.html

https://rpubs.com/crossxwill/time-series-cv