Repository navigation
ENH: add ultra-high screening with SCAD - #4683
Conversation
|
parking an idea for patch processing, no time right now user provides an iterator |
|
put However, that only covers variable addition, Dropping variables uses SCAD and we would need to penalize terms instead of columns (fused). |
Codecov Report
@@ Coverage Diff @@
## master #4683 +/- ##
==========================================
+ Coverage 80.48% 80.55% +0.06%
==========================================
Files 567 569 +2
Lines 86707 87094 +387
Branches 9772 9805 +33
==========================================
+ Hits 69787 70156 +369
- Misses 14675 14685 +10
- Partials 2245 2253 +8
Continue to review full report at Codecov.
|
|
instead of This would work as a results method a bit similarly to variable addition score/LM test.
This could even be nested, and we keep previously selected exog, which might be useful if we have hierachical terms or variables grouped by importance, e.g. or maybe it should be a model method |
| x = (np.random.rand(nobs, k_vars) + 1.* (np.random.rand(nobs, 1)-0.5)) * 2 - 1 | ||
| x *= 1.2 | ||
|
|
||
| x = (x - x.mean()) / x.std(0) |
There was a problem hiding this comment.
bug this doesn't properly standardize
needs x.mean(0)
| else: | ||
| predicted = res_pen.model.predict(p) | ||
| # this is currently hardcoded for Poisson | ||
| resid_pearson = (endog - predicted) / np.sqrt(predicted) |
There was a problem hiding this comment.
should I use resid_pearson or divided by variance (resid / variance) ?
both are orthogonality conditions but the second might correspond to WLS because exog is not weighted (i.e. is not wexog)
There was a problem hiding this comment.
Add freq_weights if in model
| resid_pearson = (endog - predicted) / np.sqrt(predicted) | ||
|
|
||
| mom_cond = np.abs(resid_pearson.dot(x1))**2 | ||
| mcs = np.sort(mom_cond)[::-1] |
There was a problem hiding this comment.
We can use now numpy partial sort using partition
But we might need to handle ties at the boundary
E.g I want to use ties for groups of exog like categorical
See threshold below
| idx_full = [(bidx, idx) | ||
| for bidx, batch in enumerate(exog_idx) | ||
| for idx in batch] | ||
| ex_final_idx = res_screen_final.idx_nonzero[1:] - 1 |
There was a problem hiding this comment.
the -1 here hard codes that exog_keep is constant only in my example, same above line 193, 194
There was a problem hiding this comment.
there is still a TODO for only indexing exog_candidates and not exog_keep
| exog_idx = [] | ||
| for ex in exog_iterator: | ||
| res_screen = self.screen_exog(ex, maxiter=20) | ||
| res_batches.append(res_screen) |
There was a problem hiding this comment.
We should not keep res_screen around, too much memory, unless it's a user option.
some history was added for debugging.
|
I added a commit "add PoissonResults resid_pearson" which can be removed if master gains it before merging this PR, see #2107 and related. Logit or GLM-Logit seems a difficult case for screening, I'm xfailing them because we don't select the right exog, at least one "true" is missing and some others are there instead. The screener options are now |
|
I guess we should also have an option to get something closer to score_test for variable addition by projecting exog candidates on included exog. |
|
tests now pass after increasing the smallest nonzero params, but there are extra variables with small params, If I increase penalization further then one or two of the true parameters gets heavily penalized and shrunk towards zero, e.g. from around 0.6 to less than 0.1. I adjusted the unit test to compare the params for the true nonzero variables ignoring the extra params. I also added projection on existing exog (currently hard coded and not an option). I think this corresponds now to the score_test statistic for adding one variable, but I didn't check the math. Choosing penalization parameters for this case will still be a problem. If the main interest is in variable selection, then we should also check wald or score tests on the final selection from the screening process. |
|
getting close to merging a bit more cleanup and early stopping in screen_exog iteration |
|
effect of stopping iteration if idx_nonzero didn't change: |
|
(last push went initially by accident into the main repo. I deleted that branch again.) last commit uses self._null_drop_keys, but I left the workaround code still in SCADSmoothed because we still need to check and fix Null for other models than subclasses of DiscreteModel. |
|
This pull request introduces 1 alert when merging a8f6bf8 into 6611e87 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
one updated notebook I'm finished with the code, I think I got everything that I wanted in this round. |
|
This pull request introduces 1 alert when merging 3f22939 into 6611e87 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
I had forgotten to respond to my own review comments |
|
This pull request introduces 1 alert when merging 9aa0d60 into 6611e87 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
almost all red, but locally tests are passing, and one appveyor passes. one failure is with a new assert that might be just on the boundary. |
|
I fixed the starting keep indices I also needed to add The test failure in |
|
This pull request introduces 1 alert when merging 2198e10 into 6611e87 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
This pull request introduces 1 alert when merging 5f90c4d into 6611e87 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
There is one more indexing problem left from my initial version: |
|
If we don't trim exog_keep, then there is no way to start with an empty model, i.e. we cannot screen all variables including constant. But it's unlikely that this will show up in usage, so it will not be supported. Using |
|
This pull request introduces 1 alert when merging 1710e78 into 6611e87 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
all green, merging, |
selecting variables for k_vars >> nobs
This is a generic function that takes a model or model class as argument to find and estimate the final model with selected exog.
requires a model with PenalizedMixing merged in #4576
Currently checked for Poisson and GLM-Poisson.
example (used for test case)
https://gist.github.com/josef-pkt/a90eb8be076276874a0d026ad6c7efa0
and GLM version
https://gist.github.com/josef-pkt/df6ef0dcf42d99dee4afeb968f4f4c94
unit tests will most likely be: "it works" and not verified against other packages
TODOs and limitations in class docstring.
API not clear yet
I'm not sure whether I want to merge a basic version or add more options.