You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Selecting Lasso via cross-validation data leakage #26359
Thanks for bringing this up, I've been wondering about our *CV classes too. Unless certain conditions are met, we always have leakage in those pipelines, and that's true for all of them (except *SearchCV taking the whole pipeline).
We should probably make that very clear, and make sure none of our examples have this issue. And I think if the user has enough CPU cycles at their hand, it's almost always safer to use a *SearchCV.
do you have empirical evidence that the alpha obtained is one option or the other is very different and that the test performance degrades with the approach model = make_pipeline(StandardScaler(), LassoCV(cv=20)).fit(X, y) ?
Using a GridSearchCV for a Lasso is a terrible waste of time as you start from scratch for each alpha. I suspect a 100x difference in running time unless you accept to have your screened filled with "ConvergenceWarning: Objective did not converge."
if you have outliers maybe use a RobustScaler? Using a RobustScaler with the snippet above I get as alphas:
66.89463732039701
66.89463732039701
So it seems to do the job.
I think my point is that people need to really know what they're doing if they use something like LassoCV. We should have very clear warnings and describe why using is might be okay, and when it can be used.
Sorry for jumping in here, but this is an issue I have been revisiting a lot lately.
The problem with the current implementation of LassoCV (and other *CV estimators like RidgeCV) is that it is quite restrictive since it is only appropriate when features in the input data are all in similar units. When features have different units (e.g. weight vs height), then you need to scale them so that some features (those with small units) do not get more penalized than others (those with large units). But you can't create a pipeline like @nielsbijl showed, because that would cause data leakage. So the only alternative to do this properly would be through GridSearchCV, but this is less efficient compared to LassoCV.
Hi, I would like to work on this issue as part of my open-source contribution. I can update the documentation/example to address the cross-validation data leakage concern. Please let me know if I can proceed.
Activity
adrinjalali commentedon May 12, 2023
Thanks for bringing this up, I've been wondering about our
*CVclasses too. Unless certain conditions are met, we always have leakage in those pipelines, and that's true for all of them (except*SearchCVtaking the whole pipeline).We should probably make that very clear, and make sure none of our examples have this issue. And I think if the user has enough CPU cycles at their hand, it's almost always safer to use a
*SearchCV.I wonder what @agramfort thinks here.
agramfort commentedon May 12, 2023
do you have empirical evidence that the alpha obtained is one option or the other is very different and that the test performance degrades with the approach
model = make_pipeline(StandardScaler(), LassoCV(cv=20)).fit(X, y)?adrinjalali commentedon Jun 1, 2023
@agramfort as soon as there are outliers, they're not the same anymore, here's an example:
Gives these two alphas:
agramfort commentedon Jul 29, 2023
two remarks here:
66.89463732039701
66.89463732039701
So it seems to do the job.
my 2c
adrinjalali commentedon Aug 1, 2023
I think my point is that people need to really know what they're doing if they use something like
LassoCV. We should have very clear warnings and describe why using is might be okay, and when it can be used.jrasero commentedon Aug 29, 2023
Hi,
Sorry for jumping in here, but this is an issue I have been revisiting a lot lately.
The problem with the current implementation of
LassoCV(and other *CV estimators like RidgeCV) is that it is quite restrictive since it is only appropriate when features in the input data are all in similar units. When features have different units (e.g. weight vs height), then you need to scale them so that some features (those with small units) do not get more penalized than others (those with large units). But you can't create a pipeline like @nielsbijl showed, because that would cause data leakage. So the only alternative to do this properly would be throughGridSearchCV, but this is less efficient compared toLassoCV.How hard would it be to implement a scale step within
LassoCV? In fact, common libraries in R (https://glmnet.stanford.edu/articles/glmnet.html) and MATLAB (https://www.mathworks.com/help/stats/lasso.html) implementing a similar function perform a scaling operation by default (it can be turned off though).agramfort commentedon Aug 30, 2023
at this point if you really want to do this I would suggest you use an older version of sklearn that had the "normalize" parameter for LassoCV.
Barath-kalidass commentedon Sep 16, 2026
Hi, I would like to work on this issue as part of my open-source contribution. I can update the documentation/example to address the cross-validation data leakage concern. Please let me know if I can proceed.