Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

robust linear model not converging for very simple case? #2425

Closed
patrickhoebeke opened this issue May 27, 2015 · 2 comments
Closed

robust linear model not converging for very simple case? #2425

patrickhoebeke opened this issue May 27, 2015 · 2 comments

Comments

@patrickhoebeke
Copy link

Hello,

It seems that there is a bug in the robust linear model
Using statsmodels '0.6.1', the following code freezes the python console.
This snippet is simply trying to fit a very simple linear dataset y = 10.x

from statsmodels.robust.robust_linear_model import RLM as sm_RLM
from statsmodels.tools.tools import add_constant as sm_add_constant

x = np.arange(0,10,1)
y = np.range(0,100,10)


model = sm_RLM(y,sm_add_constant(x))
result = model.fit()

Am I wrong ?

@josef-pkt
Copy link
Member

which operating system are you on?

My guess is that, if the interpreter becomes frozen and works full cpu time, then the linear algebra library BLAS/Lapack cannot handle nans or infs. Something similar happened to me in the past with ATLAS on Windows. Other libraries like MKL raise an exception for invalid values.

The main point is that RLM has problems handling perfect prediction. If there is no noise, then the variance is zero, and we end up with a 0/0 nan or x/0 infs that might be used in some linalg operations (pinv/svd).

Short term solution is to add a little bit of noise if it's a perfect prediction case,
y = y + 1e-6 * np.random.randn(y.shape[0])
or something like this.

There is a branch/PR waiting that tries to make the zero variance case more robust, but I don't know if I will get back to it very soon.

@bashtage
Copy link
Member

Fixed in master.

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

No branches or pull requests

3 participants