Skip to content

ENH: penalized MLE - #2374

Closed
josef-pkt wants to merge 23 commits into
statsmodels:masterfrom
josef-pkt:penalized_mle_scad
Closed

josef-pkt wants to merge 23 commits into
statsmodels:masterfrom
josef-pkt:penalized_mle_scad

Conversation

@josef-pkt

Copy link
Copy Markdown
Member

first commit is adding base._penalties.SCAD
hessian/deriv2 not tested yet

now also with PenalizedMixin and _fit_zeros

open questions:

  • Runtime Warnings: by design if bse are zero, silence them or not?
  • use skip_hessian if we don't use it, or only use it to get an array to overwrite
    Runtime Warning "inverting hessian failed" in singular exog case, but we work around

review penalties

  • I added axis 0 to the sum in return of func, so it can be used in vectorized form
  • naming conventions: I have problems remembering grad instead of deriv or score or whatever
    also weights should be spelled out
  • sum in func surprised me initially, but I guess it makes sense.
  • I haven't converted my examples to unit tests yet.
  • analytical and default numerical second derivatives are missing. (needed for Hessian)
  • other penalization functions (MCD, XXXNet versions to combine with L2)

PenalizedMixin

My initial notebook is here to try out different things http://nbviewer.ipython.org/gist/josef-pkt/1847e9af6092da12b192
I only used Poisson to check the more complete class

open issues

  • many TODOs in first draft
  • argument handling, signatures
  • main missing requirement: creating results instance, need new helper method used in seveal places. I reuse fit_constrained for Poisson which is not available for many other models and is computationally inefficient because it doesn't special case dropping variables.
  • I used cov_type='HC0' in some examples in notebook but it's not yet implemented and default in the Mixin
  • possible problem with fit defaults if they are incompatible, I partially handled IRLS for GLM, but haven't tried it out yet.
  • extension to other optimizers, Kerby's coordinate descend

_fit_zeros and recreating results instances

Since we need it in several places this includes now also a new method to fit zero restrictions (dropping variables) which can be reused by other fit_xxx methods. The main purpose was to get a trial version for creating a results instance for the full model from a reduced or reparameterized auxiliary model.

As application of _fit_zeros it also contains a new _fit_collinear

References

So far all my scad code is based on several article by Fan Li 2001, additional articles of either with co-authors.

They mention some R packages, and I just saw http://cran.r-project.org/web/packages/mpath/index.html
which should be useful for unit tests and comparison. includes count models and sandwiches.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.12%) to 83.78% when pulling c11e47d on josef-pkt:penalized_mle_scad into a1f53b0 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member Author

@kshedden I added the first draft of the PenalizedMixin with Poisson as test case

The unit tests compare PoissonPenalized with unpenalized and oracle estimators. I haven't looked at the same in R yet.

There are several open issues on the design, and we still need a reusable way to get a trimmed/reduced final results instance. I will add some notes to the description.

@josef-pkt

Copy link
Copy Markdown
Member Author

as expected. problems with python 2 (on TravisCI)

    def __init__(self, *args, penal=None, **kwds):
                                  ^
SyntaxError: invalid syntax

getting to a good python 2 compatible signature is still unclear

@josef-pkt

Copy link
Copy Markdown
Member Author

The last commit ENH: add LikelihoodModel._fit_zeros, several hacks see #2393 adds generic test for a new _fit_zeros method, and tries out one way to create new results instances for the full model with results from a auxiliary model. The pattern is similar or the same as in fit_constrained but tested on a larger set of models including RLM and OLS, WLS.
no cov_type unit tests yet and it won't work correctly.

see #2393 about problems in "retrofitting" an existing results instance.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.05%) to 83.95% when pulling 08c919d on josef-pkt:penalized_mle_scad into a1f53b0 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member Author

a computational comment to previous commit _fit_zeros:
This and similar methods should be overwritten by linear models (OLS) because they can take advantage of the linear algebra (QR decomposition) without starting from scratch with a new model.

         there are at least two test failures because of differnt optim options
@josef-pkt

Copy link
Copy Markdown
Member Author

The previous commit with _fit_collinear also has an additional LinalgError (hessian is singular) that I don't get on my computer, https://travis-ci.org/statsmodels/statsmodels/jobs/62501337
(There shouldn't be any if the collinear columns are properly trimmed/dropped, unless there are other usual convergence problems in an example.)

@josef-pkt

Copy link
Copy Markdown
Member Author

The linalg error is still there,
ERROR: statsmodels.base.tests.test_generic_methods.TestGenericNegativeBinomial.test_zero_collinear
all precision issues are settled, because the unit tests now use identical start_params and method to replicate

@josef-pkt

Copy link
Copy Markdown
Member Author

I opened issue #2406 for the change in "REF: NegativeBinomial skip_hessian for start_params" c3791cb

@josef-pkt
josef-pkt force-pushed the penalized_mle_scad branch from 6e411ed to 3fff63f Compare May 15, 2015 12:54
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.06%) to 83.97% when pulling 75daa79 on josef-pkt:penalized_mle_scad into 4d56c70 on statsmodels:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.07%) to 83.97% when pulling ac015ec on josef-pkt:penalized_mle_scad into 4d56c70 on statsmodels:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.08%) to 83.99% when pulling 4012157 on josef-pkt:penalized_mle_scad into 4d56c70 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member Author

cov_type HC0 tests for _fit_collinear also pass
adding LogitPenalized unit tests also pass, with some twisting of test tolerance (optimization randomness)

next todo: unit tests for penalized with cov_type

It's working (but the special casing is not really pretty)

@josef-pkt

Copy link
Copy Markdown
Member Author

still incorrect with PenalizedMixin: auxiliary regression doesn't use the correct penalization (pen_weight and penal). Those are given by the default and the correct values are not transmitted to the auxiliary regression.

I don't know if there is already a way to do it in _fit_zeros, recreating model is supposed to work through init_kwds

@josef-pkt

Copy link
Copy Markdown
Member Author

should we allow a set_attributes method on the model like scikit-learn?
I extended _init_keys and penal and pen_weights get transmitted correctly.

Still todo: modified results instance does not have correct cov_type info yet, if cov_type is not 'nonrobust'

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.1%) to 84.01% when pulling 7cb259e on josef-pkt:penalized_mle_scad into 4d56c70 on statsmodels:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.1%) to 84.01% when pulling e701712 on josef-pkt:penalized_mle_scad into 4d56c70 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member Author

I'm working now with knot selection by SCAD penalization for regression splines.

I just found a paper that seems to be close to what I'm doing (for Poisson example) (not read yet)
http://link.springer.com/article/10.1007/s10463-009-0242-4
Antoniadis, Anestis, Irène Gijbels, and Mila Nikolova. 2009. “Penalized Likelihood Regression for Generalized Linear Models with Non-Quadratic Penalties.” Annals of the Institute of Statistical Mathematics 63 (3): 585–615. doi:10.1007/s10463-009-0242-4.

There are several other articles with LASS0 and Bridge with pre-selected knot or discontinuity points.

@DonBeo This might be an interesting background reading (skipping technical details) for what we might do after GAM with L2 penalized splines.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.1%) to 84.0% when pulling 750e3eb on josef-pkt:penalized_mle_scad into 4d56c70 on statsmodels:master.

@coveralls

coveralls commented Jan 23, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-52.9%) to 31.045% when pulling 750e3eb on josef-pkt:penalized_mle_scad into 4d56c70 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member Author

merged in #4576

@josef-pkt josef-pkt closed this May 21, 2018
@josef-pkt
josef-pkt deleted the penalized_mle_scad branch May 21, 2018 18:29
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.

2 participants