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

LogisticGAM and LinearGAM .fit() throws ValueError: cannot set WRITEABLE flag to True of this array #271

Open
tlasko opened this issue May 18, 2020 · 5 comments · May be fixed by #288
Open

Comments

@tlasko
Copy link

tlasko commented May 18, 2020

Trying to use what looks like a promising package, but it chokes on all attempts to fit a model. Minimum example using random data, but it also happens with real data:

>>> import numpy as np
>>> from pygam import LogisticGAM, s
>>> clf=LogisticGAM(s(0)).fit(np.random.rand(10), np.random.randint(2, size=10))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/Tom/opt/anaconda3/envs/ml38/lib/python3.8/site-packages/pygam/pygam.py", line 920, in fit
    self._pirls(X, y, weights)
  File "/Users/Tom/opt/anaconda3/envs/ml38/lib/python3.8/site-packages/pygam/pygam.py", line 705, in _pirls
    E = self._cholesky(S + P, sparse=False, verbose=self.verbose)
  File "/Users/Tom/opt/anaconda3/envs/ml38/lib/python3.8/site-packages/pygam/pygam.py", line 485, in _cholesky
    L = cholesky(A, **kwargs)
  File "/Users/Tom/opt/anaconda3/envs/ml38/lib/python3.8/site-packages/pygam/utils.py", line 59, in cholesky
    P[np.arange(len(p)), p] = 1
  File "/Users/Tom/opt/anaconda3/envs/ml38/lib/python3.8/site-packages/scipy/sparse/lil.py", line 336, in __setitem__
    IndexMixin.__setitem__(self, key, x)
  File "/Users/Tom/opt/anaconda3/envs/ml38/lib/python3.8/site-packages/scipy/sparse/_index.py", line 99, in __setitem__
    i, j = _broadcast_arrays(row, col)
  File "/Users/Tom/opt/anaconda3/envs/ml38/lib/python3.8/site-packages/scipy/sparse/_index.py", line 26, in _broadcast_arrays
    y.flags.writeable = b.flags.writeable
ValueError: cannot set WRITEABLE flag to True of this array

Also happens using the example from the documentation:

from pygam.datasets import wage
>>> X, y = wage()
from pygam import LinearGAM, s, f
>>> gam = LinearGAM(s(0) + s(1) + f(2)).fit(X, y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/Tom/opt/anaconda3/envs/ml38/lib/python3.8/site-packages/pygam/pygam.py", line 920, in fit
    self._pirls(X, y, weights)
  File "/Users/Tom/opt/anaconda3/envs/ml38/lib/python3.8/site-packages/pygam/pygam.py", line 705, in _pirls
    E = self._cholesky(S + P, sparse=False, verbose=self.verbose)
  File "/Users/Tom/opt/anaconda3/envs/ml38/lib/python3.8/site-packages/pygam/pygam.py", line 485, in _cholesky
    L = cholesky(A, **kwargs)
  File "/Users/Tom/opt/anaconda3/envs/ml38/lib/python3.8/site-packages/pygam/utils.py", line 59, in cholesky
    P[np.arange(len(p)), p] = 1
  File "/Users/Tom/opt/anaconda3/envs/ml38/lib/python3.8/site-packages/scipy/sparse/lil.py", line 336, in __setitem__
    IndexMixin.__setitem__(self, key, x)
  File "/Users/Tom/opt/anaconda3/envs/ml38/lib/python3.8/site-packages/scipy/sparse/_index.py", line 99, in __setitem__
    i, j = _broadcast_arrays(row, col)
  File "/Users/Tom/opt/anaconda3/envs/ml38/lib/python3.8/site-packages/scipy/sparse/_index.py", line 26, in _broadcast_arrays
    y.flags.writeable = b.flags.writeable
ValueError: cannot set WRITEABLE flag to True of this array

Using Python 3.8.2
pygam 0.8.0
scikit-learn 0.22.2.post1
scikit-sparse 0.4.4
scipy 1.4.1

@jancurse
Copy link

jancurse commented Jun 1, 2020

I can confirm the same problem using:
python 3.7.4
pygam 0.8.0
scikit-learn 0.23.1
scikit-sparse 0.4.4
scipy 1.4.1
numpy 1.18.4

I also tried downgrading numpy to 1.15.4 (after reading a similar issue has been solved like this) but it didn't work.

@jerheff
Copy link

jerheff commented Aug 21, 2020

I received the same error, but uninstalling scikit-sparse fixed it.

@bhishanpdl
Copy link

I had the same problem. I fixed it by uninstalling scikit-sparse as suggested by jerheff.

conda uninstall scikit-sparse

Code to check:

from pygam.datasets import wage
X, y = wage()
from pygam import LinearGAM, s, f
gam = LinearGAM(s(0) + s(1) + f(2)).fit(X, y)

My versions

pygam   0.8.0
seaborn 0.10.1
pandas  1.0.5
sklearn 0.23.1
json    2.0.9
numpy   1.17.5
scipy   1.5.0

craymichael added a commit to craymichael/pyGAM that referenced this issue Jan 9, 2021
Require that the fill-reducing permutation P of Cholesky factorizer owns its data before use. Fixes dswah#271
@craymichael craymichael linked a pull request Jan 9, 2021 that will close this issue
@craymichael
Copy link

Hi, I believe I have fixed this issue - see #288

In the meantime you can fix manually or use my fork instead

@mlldantas
Copy link

I have the same issue. I had to uninstall scikit-sparse to make LinerGAM work.
I did understand how this issue was fixed (#288).

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

Successfully merging a pull request may close this issue.

6 participants