Repository navigation
GSOC2017 Zero-Inflated models - #3755
evgenyzhurko wants to merge 43 commits into
Conversation
|
@evgenyzhurko I think the discrete_models.py module is getting too large, especially because there are still more models coming. |
| w = self.model_infl.predict(params_infl) | ||
| llf_main = self.main_model.loglikeobs(params_main) | ||
|
|
||
| llf = np.zeros_like(y) |
There was a problem hiding this comment.
it's better to add the dtype here, np.float64, otherwise it will break if endog is int
| exog_infl=exog_infl, | ||
| exposure=exposure, | ||
| missing=missing, **kwargs) | ||
| self.main_model = Poisson(endog, exog) |
There was a problem hiding this comment.
switch name to model_main so it similar to model_infl
|
I just had a quick look and it looks good so far, the structure looks fine. a tip: I usually have an example script file during development in a separate process that I can run before I have unit tests. This catches basic mistakes like import errors or undefined variables. (if they don't show up in the editor already with flake or other code inspection tool.) |
|
an early comment to possible convergence problems (because I just sorted some articles with two part estimation): If we run into convergence problems, then it might be better to implement zero-truncated Poisson before resolving those. Zero-truncated should provide good starting values for the Zero-Inflated version, and we can estimate the two parts separately for the start_params. |
|
@josef-pkt I didn't implement predict for counts, because it's need to implement zero inflated poisson distribution. Will all good with rebase, when i'll try to add same files from different branch? |
|
from which branch do you want to add files? The main problem is that merging two branches with overlapping files will cause merge conflicts and possibly require interactive rebase, instead of a simple rebase. (I'm trying to do computer repair and maintenance, and expect that I can go back to this in a few days.) |
|
If you add the file in a commit without other changes, then it will be easy to skip the commit during interactive rebase, or regular rebase might recognize it as an empty commit and skip without special handling. |
|
@josef-pkt |
|
"prob" is ok, prob-count is a bit redundant in the "count" addition Sometimes I use multiple aliases for user options if there is no obvious easy to remember word. e.g. |
|
|
||
| """ | ||
| params_infl = params[self.k_exog:] | ||
| params_main = params[:self.k_exog] |
There was a problem hiding this comment.
this will be difficult for negative binomial and generalized poisson with extra params.
maybe put params_infl first and cut at k_exog_infl, so that params_name could be lenght k_exog or k_exog + 1 for extra_params
|
|
||
| .. math:: \\ln\\lambda_{i}=x_{i}\\beta | ||
| """ | ||
| return approx_fprime(params, self.loglike) |
There was a problem hiding this comment.
this could get the generic chain rule for derivatives, that uses the partial derivatives/score from the two models, main and infl.
|
I just had a very quick look, generic score looks good. |
|
@josef-pkt I tried to implement hessian. I successfully implemented d2l/dw2 and d2l/dwdparams but i have problem with d2l/dparams2. So, i don't know how to avoid this problem. |
| zero_idx = np.nonzero(y == 0)[0] | ||
| nonzero_idx = np.nonzero(y)[0] | ||
|
|
||
| llf = np.zeros_like(y) |
There was a problem hiding this comment.
This needs to make sure it is float64, in case y is still int
|
@josef-pkt During implementing Truncated model i found error in GenericZI and ZIP and Truncated. Now about ZIP model: it's very strange that it works now. We can avoid implementation score and hessian for observations with I hope you are understood what I tried to explain. |
|
It looks like it's getting close to being finished. There are some parts where computations could be rearranged, but the important part is that the computation work correctly and are tested. (and maybe some details that I have to verify again when I have updated my checkout to the latest version of this PR) |
|
This pull request introduces 25 alerts - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
This pull request introduces 25 alerts - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
Predicted |
|
This pull request introduces 25 alerts - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
small problem: predict prob raises exception if exog_infl s 1-dimensional, the other |
|
after updating my checkout to current version: all optimizer that I had tried converge to the same results for ZeroInflatedGeneralizedPoisson based on default start_params |
| params_infl = params[:self.k_inflate] | ||
| params_main = params[self.k_inflate:] | ||
|
|
||
| prob_main = 1 - self.model_infl.predict(params_infl, exog_infl).mean() |
There was a problem hiding this comment.
I think there should NOT be a .mean() here
The returned which='prob-main' needs to have the same length or nobs as the exog.
Also, I think in the computation of the other which, it should use the observation or exog specific prob_main and not the average prob_main
|
@evgenyzhurko What's the test coverage for the different predict options? If needed, I can help coming up with some unit tests for the predict options given that I have tried them out now for some time. |
|
Additional unit tests will be useful. I also can't find solution to avoid problem with nan, when i use exposure in _predict_prob for ZeroInflatedPoisson model. In other models all is good. |
|
I haven't looked at I only checked ZeroInflatedPoisson docstring in my notebook, and it is still missing the inflation arguments in |
|
This pull request introduces 25 alerts - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
@evgenyzhurko do you still have any open changes for this PR? I would like to take this over and make a few more changes before merging. |
|
@josef-pkt No, i have no any changes for now. One open issue is inflation arguments in |
This model include following models:
Each model include this parts:
Status: - reviewing, need to implement better way to generate start_params
Last commit for end of GSoC17: Changed way to find start params