Repository navigation
ENH/WIP Generic elastic net code - #2385
Conversation
|
Good to see this, I will start to look at it in a few days. aside about the mixins: The main reason for it right now was that I'm using the standard scipy optimizer via the main A second reason to combine this with the Mixin version is if we want to share and unify the Another aside: I just saw that SAS switches optimizer in an unrelated model/procedure between bfgs, quasi-newton and steepest descent (IIRC) depending on the number of parameters that need to be estimated. We might also recommend different versions of penalized estimation depending on the scale of the data once we get the different versions implemented. |
|
As FYI: |
There was a problem hiding this comment.
spelling method is loglike no dash
|
I did a quick skimming and spot reading. I didn't read enough yet to understand all the bullet items in the PR description. I think it looks very good overall. Changes to existing code will need another backwards compatibility review, but I didn't see any problems.
We still need to do more work in unifying internal APIs across models. My guess is that we still run into problems recreating results instances. As a quick check whether the most important results are available in a results instance, I usually use a smoke test for About the returned results (i didn't go through all the details yet): I will go over some details again and run some examples in a few days, after getting some other things out of the way. |
|
For performance: In the long term, I would like to refactor and add code so we can avoid creating new model and results instances repeatedly in loops, if that turns out to be costly. see #2287 It won't be immediately relevant for this. It's better to rely on generic code in the first round, but eventually we could add some private methods to the models for computational shortcuts when we don't need all the extra features that we have added to the models and results. |
|
Another still open issue for the results instance that I just remembered PR for current discrete For my PenalizedMixin version I was experimenting with returning |
|
@kshedden I started to work on a first version for creating results instances from a auxiliary regression in #2374 I think we can largely skip creating the correct results instance in this PR, and try to develop it in a setting that is easier to unit test across models. I ran into several problems in #2374 that require more refactoring or a different approach. We should merge the consistency improvements in the models, GLM, linear models, ..., soon(ish), so we have a common basis to write the various generic extensions (I will soon go back to maintenance to get 0.7 out of master, so we can merge several of the waiting PRs. It's starting to get annoying to have code spread over related but distinct branches and PRs.) |
4f4a981 to
7c24599
Compare
7c24599 to
4f22704
Compare
| from statsmodels.tools.numdiff import approx_fprime_cs | ||
| # TODO: diag workaround proplem with numdiff for 1d | ||
| return np.diag(approx_fprime_cs(mu, self)) | ||
| return np.zeros_like(mu) |
There was a problem hiding this comment.
There is a problem now with inheriting from VarianceFunction
We need to decide whether it is a base class that can be used for inheritance or a default constant variance class.
I think the only example for user defined variance function is in my risk ratio experiments with Poisson that has almost Binomial variance.
There was a problem hiding this comment.
I think we will be better off introducing a separate Constant variance class.
But, AFAIK there is currently no usecase anymore for inheritance from VarianceFunction inside statsmodels.
|
The scale handling in the regression linear model looks fine, I don't expect any problems with this way, and it makes it more usable for other cases. I'll try to read roughly through the elastic net code itself in the next few days. |
| from numpy.testing import assert_equal | ||
| llf_r = plf(params) | ||
| llf_sm = plf(sm_result.params) | ||
| assert_equal(np.sign(llf_sm - llf_r), 1) |
There was a problem hiding this comment.
numpy.testing also has a assert less
|
I went briefly through the latest changes and spot checked a few of the overall changes (for GLM) looks fine to me. I guess we will need some followups until this is settled but I think we should merge it soon. ready to merge? |
|
Thanks for the review. Let me look it through it one more time then we can On Fri, May 6, 2016 at 8:49 PM, Josef Perktold [email protected]
|
|
@josef-pkt OK, went through this again, I think we should merge it. |
|
Good, merging Thanks, to a penalized future |
This is a generic elastic net implementation that will work with any model that implements log-likelihood, score, and Hessian. It replaces the previous elastic net code that was duplicated between OLS regression and proportional hazards regression. The new code is also used to add regularization to GLM.
Notes:
GLMResultswere needed: there is no generic way to attachmuto results, so instead we usefittedvalues(same thing) instead ofmuin the results.GLM: moved some code fromfitinto__init__so thatloglike, etc. can be called without callingfitfirst.test_glm: the "hacked" version of Poisson with offsets was incompatible with the refactored GLMResults, so instead I created a proper set of R results for the Poisson offset fit to cpunish.scale=1parameter toPHRegResults-- the results need to follow a generic signature to work with elastic net.fit_regularized, moving some named arguments into kwargs. I'm not sure if it breaks compatibility. I think we should do this so that we can implement various types of regularized fitting according to the 'method' argument, and each method will have its own set of keywords as appropriate.loglikeforGLM(arguments in wrong order). Loglike is not used much since we usually do IRLS. Surprisingly it passed the tests with the arguments in the wrong order.fit_regularizedcan be run with the loss function being either the residual sum of squares, or the profile log likelihood. Only the former is comparable to R.