Repository navigation
PERF: Implement a minimal WLS for use in iterative estimation - #3048
Conversation
|
I'm adding 0.9, too late for 0.8 |
|
@bashtage Thanks, Do you know what the speed improvement is with this? |
|
About a factor of 3 -- pinv is easily the fastest of pinv, qr and lstsq. On Mon, Jun 20, 2016 at 10:53 PM Josef Perktold [email protected]
|
|
#2203 most likely we should move this to the special models in regression |
| """ | ||
| normalized_cov_params = None | ||
| if method == 'pinv': | ||
| pinv_wexog = np.linalg.pinv(self.wexog) |
There was a problem hiding this comment.
Is there a way that we could pinv on self.exog only once? Seems like this will run every iteration and the result shoudl be same every time, if I understand correctly.
There was a problem hiding this comment.
On second thought, this is wexog, and the weight should change every iteration as mu updates. Never mind.
There was a problem hiding this comment.
Yes, the weight changes and so it isn't possible to improve that step.
One source of slowness is the sheer number of statistics that need to be
computed for the update dictionary - residuals, whitened residuals, scale.
For moderate datasets these impact speeds. For very large datasets, pinv
dominates.
On Tue, Jun 21, 2016 at 3:49 AM Peter Quackenbush [email protected]
wrote:
In statsmodels/regression/_tools.py
#3048 (comment)
:
\* resid : Residuals using original data\* normalized_cov_params\* model : namedtuple with one field, weights\* scale : scale computed using weighted residuals
Notes
Does not perform and checks on the input data
See Also
statsmodels.regression.linear_model.WLS"""normalized_cov_params = Noneif method == 'pinv':pinv_wexog = np.linalg.pinv(self.wexog)On second thought, this is wexog, and the weight should change every
iteration as mu updates. Never mind.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/statsmodels/statsmodels/pull/3048/files/764e8deafd2470c1995a64f5cf417b4c9d8f8823#r67800816,
or mute the thread
https://github.com/notifications/unsubscribe/AFU5RbtA_ajB5eEWz-CPCBFiO3gnl__iks5qN1FHgaJpZM4I6DXV
.
bf1126e to
27c549a
Compare
|
I tested with a very large dataset - 30,000 observation. Using |
|
I think @kshedden made some improvements to remove obvious inefficiencies and so there isn't alot, other than using lstsq which is a bit faster. The testing was with GLM using the notebook example using |
|
In a large RLM with 1000000 obs master takes 10s for fit and this lstsq takes 5s. Using lstsq is definitely helpful, but it isn't clear whether a dedicated class/function is better than adding lstsq as a fit option to WLS. |
|
you switched to numpy lstsq which I think also uses svd, so any sizable differences would be surprising, or it uses a better setting for svd. One possibility at the cost of loosing precision would be to use the normal equations directly which might be faster for large nobs but not large k_vars. @thequackdaddy is working with a few million observations in GLM. |
|
(I'm intermittently loosing internet now, fortunately after the rc release.) are you doing the timing just for pinv/lstsq or including cov_params? |
|
Numpy uses |
The times reported are just for the |
99aa97f to
ecaa2d8
Compare
| from collections import namedtuple | ||
| import numpy as np | ||
|
|
||
| _MinimalWLSResults = namedtuple('_MinimalWLSResults', |
There was a problem hiding this comment.
It is better to make this into simple Dummy/Holder/Bunch classes.
tuples are not forward compatible if we want to change what is returned.
| else: | ||
| params, _, _, _ = np.linalg.lstsq(self.wexog, self.wendog) | ||
|
|
||
| model = _MinimalWLSModel(weights=self.weights) |
There was a problem hiding this comment.
What's the purpose of adding this Model class?
Why not just use self, which is already a model class?
|
I think we should merge this soon. Some future ideas: This PR is fully backwards compatible (except for maybe some near singular corner cases), we don't have to settle on a new API yet. (*) checking this: it uses data augmentation to implement the penalty, instead of solving the Theil/Ridge moment conditions directly |
|
Named tuple is not a tuple. It is a Python provided collection that is
similar to a bunch without requiring a user provided class. It uses
attribute access. Future can easily add attributes as needed.
…On Thu, Feb 9, 2017, 18:35 Josef Perktold ***@***.***> wrote:
I think we should merge this soon.
Some future ideas:
I think we make this swappable. We can use the same pattern for WLS that
have a different structure, e.g. ridge penalized or sparse matrices.
(something similar for structured Ridge/L2 penalization is in the
GAM/penalized spline PR (*). a draft version of SparseOLS is in #2711
<#2711>)
For this we will need to eventually fix a internal API for the
MinimalWLSXxx classes and their use in IRLS.
This PR is fully backwards compatible (except for maybe some near singular
corner cases), we don't have to settle on a new API yet.
(*) checking this: it uses data augmentation to implement the penalty,
instead of solving the Theil/Ridge moment conditions directly
https://github.com/statsmodels/statsmodels/pull/2744/files#diff-c83444952c95fc7854675f85758d9006R329
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3048 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFU5RW4vD3FoD-GZUthJLlYTTh_n5kRgks5ra1xkgaJpZM4I6DXV>
.
|
|
but it allows tuple unpacking and slicing/indexing, which breaks when we want to change the number of returns (that's a problem that scipy, especially scipy.stats, has for making changes, and we have it also with most of the hypothesis tests) |
7c5a861 to
a9387b9
Compare
Implement minimal WLS that computes the bare minimum needed for GLM and RLM model estimation. closes statsmodels#2287
Covariance isn't commonly needed and one extra fit of WLS can be used to produce the normalized cov when required
Remove use of namedtuple in favor of Bunch Provide a single, best practice definition of Bunch Refactor all uses to use single definition of Bunhc
a9387b9 to
b3f4a6e
Compare
josef-pkt
left a comment
There was a problem hiding this comment.
I added a few comments, mainly spot checking the unit tests.
|
sorry last comment was for a different PR, I must have switched browser windows by accident. |
|
in it goes @bashtage Thank you |
Implement minimal WLS that computes the bare minimum needed
for GLM and RLM model estimation.
closes #2287