Skip to content

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

@tlasko

Description

@tlasko

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions