I am trying to apply rolling cross-validation (or expanding window cross-validation) in MATLAB using the lasso function for time series data. I found the tspartition function, which seems suited for time series partitioning, but I am encountering an error when trying to use it with lasso.
Here’s the code I am currently using:
rng('default')
X = rand(10,5);
y = 2 + X * [2 * rand(5,1) - 2 * rand(5,1)] + randn(10,1);
LambdaValues = logspace(-4, 1, 100);
CV = tspartition(size(X,1), 'ExpandingWindow', 5);
[B, FitInfo] = lasso(X, y, 'CV', CV, 'Lambda', LambdaValues, 'Standardize', false, 'Intercept', true);
However I get:
Error using classreg.learning.generator.Partitioner.processArgs (line 126)
'CVPartition' value must be a cvpartition object.
Error in lasso (line 513)
The parameter 'CV' must be a positive integer or a partition created with CVPARTITION. It may not be a
'Leaveout' partition.
It seems that tspartition is not compatible with lasso since the latter requires a cvpartition object. Is there a way to implement rolling or expanding window cross-validation for time series data with lasso in MATLAB? How can I achieve this without getting the error?