Skip to content

TST: de-duplicate a ton of test code for IRLS - #4936

Closed
jbrockmendel wants to merge 4 commits into
statsmodels:mainfrom
jbrockmendel:brevity
Closed

jbrockmendel wants to merge 4 commits into
statsmodels:mainfrom
jbrockmendel:brevity

Conversation

@jbrockmendel

Copy link
Copy Markdown
Contributor

This can be simplified way further if my guess about #4935 is right.

@josef-pkt

Copy link
Copy Markdown
Member

I only briefly skimmed this

I'm not sure this is the right approach or split of functions #4612
i.e. needs careful review and some thoughts about the structure for reusable components for additional test cases in future.

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

What approach do you have in mind? I’m open to suggestions.

@josef-pkt

Copy link
Copy Markdown
Member

I'm not sure, I haven't thought much about the details
some thoughts
a new module should only have helper function or classes but not unit tests directly. I don't like the splitting out of test functions into test_irls because irls is just an method option in the regular classes and conceptually it doesn't belong in a separate module.

helper function or class or other object should include a list of all combinations and generate datasets, similar to what's in the current loops. My guess is that this needs an option to provide exog, e.g. I have been working recently often with the two sample case (constant + 1 dummy variable).
The final target would be something that can easily be reused for additional functionality in future, e.g. something that statsmodels base generic tests are also useful for.

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

Fair enough. While I start in on another pass at this, any thoughts on #4935?

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

Re-written so as to not create a new file. Written with an eye towards parametrizing in the medium-run. Ideally these big loops would be separate tests and we would xfail non-convergent cases instead of skipping them. That way we know when they get fixed.

The only actual change in logic here is in the value lin_pred takes in test_glm_weights in the cases with (family_class, link) == (fam.NegativeBinomial, lnk.identity). In master this clips at 1e-3, while the two tests in test_glm clip at 1e-4. This makes them all clip at 1e-4.

One difference in behavior that it would be nice to standardize: lin_pred in the case with (family_class, link) == (fam.Poisson, lnk.sqrt) is lin_pred = 2 + exog.sum(1) for the two tests in test_glm, but lin_pred=-2 + exog.sum(1) for the test in test_glm_weights. If there isn't a compelling reason for the difference, it would be nice to not need the special case.

@josef-pkt

Copy link
Copy Markdown
Member

If there isn't a compelling reason for the difference, it would be nice to not need the special case.

My guess is that the difference in the poisson case is irrelevant but that one was an attempt to find a nicer case for convergence.
However, we often need special cases when we look at different types of models, behavior or corner cases. In those cases we need separate functions or functions that are general enough to allow for different "special" cases by design.
That means that the helper functions or classes need to be flexible enough to create those different special cases.

@coveralls

coveralls commented Aug 18, 2018 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.004%) to 88.39% when pulling 26dfa0a on jbrockmendel:brevity into 52b142c on statsmodels:master.

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

Travis failure in grouputils unrelated. @josef-pkt something else relevant changed recently?

@josef-pkt

Copy link
Copy Markdown
Member

about travis test failure: I didn't find any changes in the environment at the time when the failure started to show up, The dependencies that I checked, numpy, scipy, pandas, cython and some spot checking for others all seem to be the same versions as before.

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

Ok. I can’t help with the appveyor one, but will look into the new Travis failure.

Identifying real errors would be much easier if the queue of easy PRs got trimmed.

@codecov-io

codecov-io commented Aug 20, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #4936 into master will decrease coverage by 2.03%.
The diff coverage is 93.39%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4936      +/-   ##
==========================================
- Coverage   86.07%   84.03%   -2.04%     
==========================================
  Files         698      613      -85     
  Lines      118309    97525   -20784     
  Branches    13131    10631    -2500     
==========================================
- Hits       101840    81960   -19880     
+ Misses      13707    13149     -558     
+ Partials     2762     2416     -346     
Impacted Files Coverage Δ
statsmodels/genmod/tests/test_glm_weights.py 98.54% <91.46%> (+0.33%) ⬆️
statsmodels/genmod/tests/test_glm.py 99.64% <100.00%> (-0.05%) ⬇️
statsmodels/stats/descriptivestats.py 23.68% <0.00%> (-63.45%) ⬇️
statsmodels/tests/test_package.py 75.00% <0.00%> (-25.00%) ⬇️
statsmodels/stats/base.py 52.94% <0.00%> (-14.41%) ⬇️
statsmodels/nonparametric/tests/test_kernels.py 89.13% <0.00%> (-10.87%) ⬇️
statsmodels/tools/docstring.py 71.12% <0.00%> (-8.30%) ⬇️
statsmodels/graphics/gofplots.py 83.95% <0.00%> (-7.64%) ⬇️
statsmodels/stats/tests/test_diagnostic.py 92.65% <0.00%> (-7.19%) ⬇️
statsmodels/stats/_lilliefors.py 91.13% <0.00%> (-6.23%) ⬇️
... and 375 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 52b142c...26dfa0a. Read the comment docs.

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

@josef-pkt green

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

@josef-pkt this isn’t just de-deuplication, it’s preparatory to identifying and then trying to fix cases with convergence problems.

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

@josef-pkt tracking down the cases with convergence problems is something you care about right? This is a step towards that goal.

@jbrockmendel jbrockmendel changed the title de-duplicate a ton of test code for IRLS TST: de-duplicate a ton of test code for IRLS Sep 11, 2018
@jbrockmendel

Copy link
Copy Markdown
Contributor Author

@josef-pkt green and no merge conflict. I'd really like to get this through so I can move on to troubleshooting the non-convergent cases.

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

@bashtage any thoughts here? Besides the virtues of de-duplication, this will go a long way towards making tests parametrizable so we can get more systematic coverage.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants