FIX: resolve sklearn 1.9 compatibility for WeightedLassoCV n_alphas deprecation (#1032 )#1046
Open
genrichez wants to merge 1 commit into
Open
FIX: resolve sklearn 1.9 compatibility for WeightedLassoCV n_alphas deprecation (#1032 )#1046genrichez wants to merge 1 commit into
genrichez wants to merge 1 commit into
Conversation
a4c2796 to
41596d9
Compare
…eprecation On sklearn >= 1.7, the n_alphas parameter in LassoCV/MultiTaskLassoCV is deprecated (removed in 1.11) in favor of passing an int to alphas. The existing version check correctly passes alphas=n_alphas to super().__init__(), but the n_alphas attribute leaked into get_params() output. When sklearn's LinearModelCV.fit() calls self.get_params() to build path_params, n_alphas was passed to lasso_path(), triggering FutureWarnings. Additionally, self.alphas was being set to None (the default) instead of the effective int value, causing InvalidParameterError at fit time. Fix: - Set self.alphas to the effective value (alphas if provided, else n_alphas) in the >= 1.7 branch - Override get_params() to exclude n_alphas from the returned dict on sklearn >= 1.7, preventing it from leaking into lasso_path() - Apply same fix to WeightedMultiTaskLassoCV Closes py-why#1032 Signed-off-by: genrichez <2.2434764e+07+genrichez@users.noreply.github.com>
41596d9 to
79d580a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
InvalidParameterErrorandFutureWarningwhen using EconML with scikit-learn >= 1.7 (wheren_alphasis deprecated) and >= 1.9 (where it will be removed).Closes #1032
Problem
In sklearn 1.7+,
LassoCVandMultiTaskLassoCVdeprecated then_alphasparameter in favor of passing an int directly toalphas. The existing version check inWeightedLassoCV.__init__correctly passesalphas=n_alphastosuper().__init__(), but two issues remained:self.alphaswas set toNone(the defaultalphaskwarg value) instead of the effective int value, causingInvalidParameterError: The 'alphas' parameter must be an int or array-like. Got None insteadat fit time.n_alphasleaked intoget_params()output. When sklearn'sLinearModelCV.fit()callsself.get_params()to buildpath_params,n_alphaswas passed tolasso_path(), triggeringFutureWarning: 'n_alphas' was deprecated in 1.9 and will be removed in 1.11.Fix
self.alphasto the effective value (alphasif provided, elsen_alphasas int) in the>= 1.7branchget_params()to excluden_alphasfrom the returned dict on sklearn >= 1.7, preventing it from leaking intolasso_path(**path_params)WeightedMultiTaskLassoCVTesting
Verified with sklearn 1.9.0:
econml.orf(triggers WeightedLassoCV init)WeightedLassoCV.fit()with default n_alphas=100WeightedLassoCV.fit()with n_alphas=1 (edge)WeightedLassoCV.fit()with n_alphas=1000 (large)WeightedLassoCV.fit()with explicit alphas arrayWeightedMultiTaskLassoCV.fit()WeightedLassoCVWrappersingle/multi-targetWeightedLassoCVWrapperwith sample_weightDebiasedLasso(uses WeightedLassoCV internally)LinearDMLend-to-end pipelinesklearn.clone()compatibilityset_params()round-tripFutureWarningabout n_alphasBackward Compatibility
WeightedLassoCV(n_alphas=50)still works on all sklearn versionsWeightedLassoCV(alphas=[0.1, 0.01])still worksget_params()/set_params()/clone()all work correctly