Repository navigation
ENH/REF/BUG Discrete models llnull improvements - #3921
Conversation
|
Bonus: I'm writing moment estimators for the dispersion coefficient, NB1, NB2, NBP, GPP. aside: count models don't have resid_pearson (discrete binary models have it) |
|
all red, problem in my new tests (locally) still have convergence problems or create a lot of warnings, test case is definitely not nice for exp. (NB1 dispersion coefficient is above 2000) |
|
test error py 2.7: |
|
The last commit should finish with the main count models. I'm not sure I will figure out the remaining null start_params for this PR, binary, MNLogit and ZeroInflated. a possible additional test is to check that null start_params are close to fit params, which should be fine if one-step moment estimators are close to MLE. another open issue is better preliminary fit to get the start_params for the final model. In the unit tests in this PR, I avoided problems by hardcoding the start_params for the full model. The test classes could check generically for convergence in this case, future task when we have a better way to get default start_params. In my initial script for this PR I used |
|
2 widespread test failure test pass in one python version on travis, and they pass locally for me |
|
on appveyor 2 out of 3 are green, one has the same two failures as travis right now I don't see a reason why bfgs should converge in one case but not the other with similar starting values. From what I can see locally there shouldn't be a difference in the model or model parameters. needs more "unit" tests for intermediate results. |
|
related to this: I did not add an option to change the optimizer arguments in the llnull fit Maybe I need to add it after all if start_params_null are not enough. |
|
New commit uses nm and newton instead of bfgs. This is mainly to check the outcome across versions. I don't think it's a good default. "bfgs" looks better for recent enough scipy versions. If it works, then we might have to add |
|
travis stopped on all versions maybe inf or nan in linalg when computing newton that hangs (although MKL usually raises instead of hangs) appveyor also hangs in count model test, but didn't stop, I canceled another puzzle: the changes use test_discrete and not test_count_model which is the last on travis and appveyor |
89a2cde to
3306615
Compare
|
amended last commit and force pushed to switch back to 'bfgs', try different settings |
|
Another way to avoid spending (wasting) a lot of time fixing unit tests for extreme cases is to skip the two tests for scipy < 0.18. |
Codecov Report
@@ Coverage Diff @@
## master #3921 +/- ##
==========================================
+ Coverage 78.92% 78.96% +0.04%
==========================================
Files 541 541
Lines 80648 80813 +165
Branches 9180 9187 +7
==========================================
+ Hits 63649 63816 +167
+ Misses 14921 14920 -1
+ Partials 2078 2077 -1
Continue to review full report at Codecov.
|
|
everything green However, I decided to add no computation, computation are lazily triggered if llnull is used directly or indirectly the intention is mainly to have an official override if the defaults fail, as in the issues that triggered this refactoring |
|
@denadai2 this should fix the llnull failures/nans in your issues, but I haven't tried with your dataset yet. |
|
The llnull problem with Poisson in #3533 is fixed by this, the new null start_params allow convergence and non-nan llnull. (In my notebook for #3533 I had used scipy '0.17.0', now I'm using 0.18.1, which might also improve convergence.) aside: In that notebook I used |
josef-pkt
left a comment
There was a problem hiding this comment.
looks fine when skimming the code
a few typos,
no doc string for internal _get_start_params_null
| Parameters | ||
| ---------- | ||
| llnull : None or float | ||
| If llnull is not None, than the value will be directly assigned to |
| If llnull is not None, than the value will be directly assigned to | ||
| the cached attribute "llnull". | ||
| attach_results : Bool | ||
| Sets and internal flag whether the results instance of the null |
| the cached attribute "llnull". | ||
| attach_results : Bool | ||
| Sets and internal flag whether the results instance of the null | ||
| model is attached. By default without calling this method, the |
There was a problem hiding this comment.
model is attached -> model should be attached
|
using a docstring template for internal functions is not so useful, because the docstring is not next to the source and the main audience are developers. |
This PR refactors llnull to use start_params provide by
model._get_start_params_null.The start_params for the null model can be obtained by moment estimators, which should make it more robust.
closes related issues:
#3533 second part is for llnull, first part is convergence failure with defaults (where users can work around)
#3476 Poisson llnull, mailing list thread has also discussion on MNLogit
#3572 NB2 llnull
related issue #3751 (is more general, e.g. penalization, constraints. I don't know yet what should/needs to be done)
This also includes now refactoring and fixes that I ran into:
#3919 avoid integer overflow in GP hessian, REF set endog, exog dtypes to at least float64
#3918 start_params needed to to provide transformed params if transformparams is used internally
closes #3533, closes #3476, closes#3572, closes #3919("closes" is needed each time)