8000 Implement L1 solver for GLM by louisabraham · Pull Request #9430 · statsmodels/statsmodels · GitHub
[go: up one dir, main page]

Skip to content

Implement L1 solver for GLM #9430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

louisabraham
Copy link
@louisabraham louisabraham commented Nov 21, 2024

Can you tell me how and where to write a test? I could try to match the results against the code in #9428

@josef-pkt
Copy link
Member
josef-pkt commented Nov 21, 2024

don't blacken the module. I will not merge it.

A pull request should only have the relevant changes, with at most a few small changes in the code that surrounds the main change.

@bashtage
Copy link
Member

Any chance you could unblack the fine? Really hard to find genuine changes.

@bashtage
Copy link
Member

We should black the entire repo, but that is a bigger discussion.


-loglike/n + alpha*(1-L1_wt)*|params|_2^2/2
loglike_kwds = {} if loglike_kwds is None else loglike_kwds

Check notice

Code scanning / CodeQL

Unused local variable

Variable loglike_kwds is not used.

-loglike/n + alpha*(1-L1_wt)*|params|_2^2/2
loglike_kwds = {} if loglike_kwds is None else loglike_kwds
score_kwds = {} if score_kwds is None else score_kwds

Check notice

Code scanning / CodeQL

Unused local variable

Variable score_kwds is not used.
-loglike/n + alpha*(1-L1_wt)*|params|_2^2/2
loglike_kwds = {} if loglike_kwds is None else loglike_kwds
score_kwds = {} if score_kwds is None else score_kwds
hess_kwds = {} if hess_kwds is None else hess_kwds

Check notice

Code scanning / CodeQL

Unused local variable

Variable hess_kwds is not used.
Comment on lines 1525 to 1533
def fit_regularized(
self,
method="elastic_net",
alpha=0.0,
start_params=None,
refit=False,
opt_method="bfgs",
**kwargs,
):

Check notice

Code scanning / CodeQL

Mismatch between signature and use of an overridden method

Overridden method signature does not match [call](1), where it is passed an argument named 'maxiter'. Overriding method [method GEE.fit_regularized](2) matches the call. Overridden method signature does not match [call](3), where it is passed an argument named 'scale'. Overriding method [method GEE.fit_regularized](2) matches the call. Overridden method signature does not match [call](4), where it is passed an argument named 'pen_wt'. Overriding method [method GEE.fit_regularized](2) matches the call. Overridden method signature does not match [call](3), where it is passed an argument named 'pen_wt'. Overriding method [method GEE.fit_regularized](2) matches the call.
)

if cov_type == "nonrobust":
self.cov_type = "nonrobust"

Check warning

Code scanning / CodeQL

Overwriting attribute in super-class or sub-class

Assignment overwrites attribute cov_type, which was previously defined in superclass [LikelihoodModelResults](1).
Comment on lines 1900 to 1904
self.cov_kwds = {
"description": "Standard Errors assume that the"
+ " covariance matrix of the errors is correctly "
+ "specified."
}

Check warning

Code scanning / CodeQL

Overwriting attribute in super-class or sub-class

Assignment overwrites attribute cov_kwds, which was previously defined in superclass [LikelihoodModelResults](1).
Comment on lines 2423 to 2432
def score_test(
self,
exog_extra=None,
params_constrained=None,
hypothesis="joint",
cov_type=None,
cov_kwds=None,
k_constraints=None,
observed=True,
):

Check notice

Code scanning / CodeQL

Returning tuples with varying lengths

GLMResults.score_test returns [tuple of size 2](1) and [tuple of size 3](2).
data = longley.load()
# data.exog = add_constant(data.exog)
GLMmod = GLM(data.endog, data.exog).fit()
GLMT = GLMmod.summary(returns='tables')
GLMT = GLMmod.summary(returns="tables")

Check notice

Code scanning / CodeQL

Unused global variable

The global variable 'GLMT' is not used.
# GLMT[0].extend_right(GLMT[1])
# print(GLMT[0])
# print(GLMT[2])
GLMTp = GLMmod.summary(title='Test GLM')
GLMTp = GLMmod.summary(title="Test GLM")

Check notice

Code scanning / CodeQL

Unused global variable

The global variable 'GLMTp' is not used.
@pep8speaks
Copy link

Hello @louisabraham! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 1478:1: W293 blank line contains whitespace

@louisabraham
Copy link
Author

Any chance you could unblack the fine? Really hard to find genuine changes.

Just did it and repushed/

@louisabraham
Copy link
Author

Hello! did you have time to look at this?

@@ -1380,8 +1380,8 @@ def fit_regularized(self, method="elastic_net", alpha=0.,

Parameters
----------
method : {'elastic_net'}
Only the `elastic_net` approach is currently implemented.
method : {'elastic_net', 'l1'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to keep the full name for l1_slsqp here

Needs comment that is an interior point method (in contrast to coordinate descent of elastic net)

@josef-pkt
Copy link
Member

Overall this looks good. I have only looked at the overall structure and not yet at the details.

It's a useful extension and can be merged after a proper review and addition of unit tests.

It should be possible to add the unit test using the corresponding unit test of discrete models, logit, poisson, ...
Also we should compare it with the elastic net results for L1 to check that we get the same or similar results (or explainable differences if the cutoffs differ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

elastic_net implementation
4 participants
0