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

why sometimes get "LInAlgError:Singular matrix" error? #67

Closed
YeoungJe opened this issue Jan 23, 2020 · 4 comments
Closed

why sometimes get "LInAlgError:Singular matrix" error? #67

YeoungJe opened this issue Jan 23, 2020 · 4 comments

Comments

@YeoungJe
Copy link

YeoungJe commented Jan 23, 2020

model = NGBClassifier(Base=default_tree_learner, Dist=Bernoulli,
Score=MLE, natural_gradient=True, verbose=False,n_estimators = 500)

Here is error


` 226 # fitting
--> 227 model.fit(train_arx,train_ary)
228 if return_proba :
229 predict_value = model.predict_proba(test_arx)

~/anaconda3/lib/python3.6/site-packages/ngboost/ngboost.py in fit(self, X, Y, X_val, Y_val, sample_weight, val_sample_weight, train_loss_monitor, val_loss_monitor, early_stopping_rounds)
119 loss_list += [train_loss_monitor(D, Y_batch)]
120 loss = loss_list[-1]
--> 121 grads = S.grad(D, Y_batch, natural=self.natural_gradient)
122
123 proj_grad = self.fit_base(X_batch, grads, sample_weight)

~/anaconda3/lib/python3.6/site-packages/ngboost/scores.py in grad(forecast, Y, natural)
13 grad = forecast.D_nll(Y)
14 if natural:
---> 15 grad = np.linalg.solve(fisher, grad)
16 return grad
17

<array_function internals> in solve(*args, **kwargs)

~/anaconda3/lib/python3.6/site-packages/numpy/linalg/linalg.py in solve(a, b)
401 signature = 'DD->D' if isComplexType(t) else 'dd->d'
402 extobj = get_linalg_error_extobj(_raise_linalgerror_singular)
--> 403 r = gufunc(a, b, signature=signature, extobj=extobj)
404
405 return wrap(r.astype(result_t, copy=False))

~/anaconda3/lib/python3.6/site-packages/numpy/linalg/linalg.py in _raise_linalgerror_singular(err, flag)
95
96 def _raise_linalgerror_singular(err, flag):
---> 97 raise LinAlgError("Singular matrix")
98
99 def _raise_linalgerror_nonposdef(err, flag):

LinAlgError: Singular matrix`


On the same data, sometimes works fine but sometimes occur errors. What should I do when this error occurs?

@YeoungJe YeoungJe reopened this Jan 23, 2020
@alejandroschuler
Copy link
Collaborator

Hi @YeoungJe , I'm not sure exactly what is causing the error withpppout being able to reproduce it myself- is it possible for you to share the data with me?

Something that should "fix" the problem is setting natural_gradient=False in the NGBClassifier constructor, but this is more of a workaround than a fix and I still want to know what it is about the data that causes the problem.

@alejandroschuler
Copy link
Collaborator

Hi @YeoungJe I'm going to close this issue for now but please get in touch again if you are still having problems and we can try and help if you provide more information.

@astrogilda
Copy link

I am having the exact same issue! @alejandroschuler any thoughts on this?

@qq492947833
Copy link

I have the same problem! This seems to be due to the use of inappropriate parameters! Such as larger learning rates, smaller max depths, and so on.

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

No branches or pull requests

4 participants