Skip to content

BUG Negbin fit regularized - #1623

Merged
josef-pkt merged 14 commits into
statsmodels:masterfrom
josef-pkt:negbin_fit_regularized
Jul 22, 2014
Merged

josef-pkt merged 14 commits into
statsmodels:masterfrom
josef-pkt:negbin_fit_regularized

Conversation

@josef-pkt

Copy link
Copy Markdown
Member

adds fit_regularized method to NegativeBinomial
fixes #1453 and #1454

note:
code is mostly copy paste see #1615
took me a while to figure out copy/paste/adjust errors for example #1617

one issue not clear:
NegativeBinomial transforms parameters in some cases, I chose not to: self._transparams = False

TODO: how can I adjust the docstring?
by default if alpha is scalar, then the penalization is not applied to the extra, shape parameter alpha of nb1 and nb2

unittests follow the same pattern as the other L1 test, compare reduced unregularized estimation with regularized estimation that doesn't penalize the original parameters

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can use use self.res_reg.model.k_exog here to make sure it's being used systematically?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

m is a setting for the test, it is here the number unpenalized beta params,
m=k_exog in the reduced version but m < k_exog in the regularized version.

in my interpreter session I don't have a model.k_exog. where is k_exog set?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right. From the description I thought that the tests were testing the unregularized vs. regularized without any actual regularization.

It looks like k_exog is only systematically set in ARIMA so far. Should be moved up to base. Still TODO in #487.

@josef-pkt

Copy link
Copy Markdown
Member Author

I'm giving up on #1624 for this PR

temporary solution:
add k_extra as attribute to NegativeBinomialModel, and adjust df_model and df_resid in L1CountResults so it isn't included.
that leaves df_model and df_resid at it's current non-L1 definition for nb1 and nb2

@josef-pkt

Copy link
Copy Markdown
Member Author

TravisCI fails in all versions
looks like a optimization problem in unregularized fit with nb2, gets a nan in params
second failure is small precision issue

two possible problems in this PR for optimization:

  • we use the full Poisson fit as starting value, which might not be very good if there are many extra variables.
  • we don't transform alpha during optimization: I haven't checked if we avoid negative alpha.

@josef-pkt

Copy link
Copy Markdown
Member Author

still red
precision failure is 2405.88524487 / 2405.85274708 - 1 = 1.3507805097123793e-05 ("amended")
why do we check f_test anyway? just to make sure some results are correct (we use normal distribution)

no idea about optimization problem, which param is nan ?

@josef-pkt

Copy link
Copy Markdown
Member Author

all green when I'm cheating with the start_params

@josef-pkt

Copy link
Copy Markdown
Member Author

ready to merge, I leave the start_params to another PR.

according to the network graph, this didn't branch off from master, might need rebase before merging

@josef-pkt josef-pkt added this to the 0.6 milestone May 22, 2014
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+1.63%) when pulling 0739786 on josef-pkt:negbin_fit_regularized into b52bc09 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member Author

That's better, after standardizing exog (mean=0, std=1) TravisCI manages to estimate correctly. No more exceptions.
Note: data transformation changes the penalization here because I didn't correct for it by adjusting alpha.

#1649 example with convergence or optimization failure

another review of this PR and it is ready to merge

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

input/argument checking should be at the beginning before we calculate anything.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.02%) when pulling 6544287 on josef-pkt:negbin_fit_regularized into 40bd7e0 on statsmodels:master.

josef-pkt added a commit that referenced this pull request Jul 22, 2014
@josef-pkt
josef-pkt merged commit a40711c into statsmodels:master Jul 22, 2014
@josef-pkt
josef-pkt deleted the negbin_fit_regularized branch July 22, 2014 11:15
PierreBdR pushed a commit to PierreBdR/statsmodels that referenced this pull request Sep 2, 2014
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.

Discrete NegativeBinomialModel regularized_fit ValueError: matrices are not aligned

3 participants