glm-tools / pyglmnet

Python implementation of elastic-net regularized generalized linear models
http://glm-tools.github.io/pyglmnet/
MIT License
279 stars 84 forks source link

Running brief example in docs raises errors #394

Closed foster999 closed 3 years ago

foster999 commented 3 years ago

Issue

Running the current brief example generates an error:

Traceback (most recent call last):
  File "e:/repos/fes-cluster-model/src/demo_model.py", line 17, in <module>
    ytrain = simulate_glm('poisson', beta0, beta, Xtrain)[:, 0]
  File "E:\Software\Anaconda\lib\site-packages\pyglmnet\pyglmnet.py", line 390, in simulate_glm
    raise ValueError("'beta0' must be float, got %s" % type(beta0))
ValueError: 'beta0' must be float, got <class 'numpy.ndarray'>

When fixing this by slicing the float out of the numpy array, another error complains that beta is a 2D array:

Traceback (most recent call last):
  File "e:/repos/fes-cluster-model/src/demo_model.py", line 17, in <module>
    ytrain = simulate_glm('poisson', beta0, beta, Xtrain)[:, 0]
  File "E:\Software\Anaconda\lib\site-packages\pyglmnet\pyglmnet.py", line 393, in simulate_glm
    raise ValueError("'beta' must be 1D, got %dD" % beta.ndim)
ValueError: 'beta' must be 1D, got 2D

Flattening the array leads to another error:

Traceback (most recent call last):
  File "e:/repos/fes-cluster-model/src/demo_model.py", line 17, in <module>
    ytrain = simulate_glm('poisson', beta0, beta, Xtrain)[:, 0]
IndexError: too many indices for array

It then seems to run if you remove the slicing when generating ytrain and ytest.

Version info

python 3.6.2 pyglmnet 1.1 numpy 1.18 scipy 1.1 sklearn 0.18.1

foster999 commented 3 years ago

Apologies, this has been resolved in the latest version of the docs (not yet live)!