bbalasub1 / glmnet_python

GNU General Public License v3.0
199 stars 93 forks source link

Can't reproduce the example using cvglmnet #69

Open egayer opened 3 months ago

egayer commented 3 months ago

Hi all,

I am having trouble using a code I wrote few years ago. In order to see if my code was the problem, although it was working fine back then, I tried to run an example from the notebook "glmnet_examples.ipynb" (https://github.com/bbalasub1/glmnet_python/blob/master/test/glmnet_examples.ipynb)

here is the example:

x = np.loadtxt(baseDataDir + 'QuickStartExampleX.dat', dtype = np.float64)
y = np.loadtxt(baseDataDir + 'QuickStartExampleY.dat', dtype = np.float64)

cvfit = cvglmnet(x = x.copy(), y = y.copy(), ptype = 'mse', nfolds = 20)

But it gives me the same error as with my old code :

raceback (most recent call last):
  Cell In[73], line 2
    cvfit = cvglmnet(x = x.copy(), y = y.copy(), family = 'binomial', ptype = 'class')

  File ~/anaconda3/envs/py3_forgeGlmnet/lib/python3.10/site-packages/glmnet_python/cvglmnet.py:244 in cvglmnet
    glmfit = glmnet(x = x, y = y, family = family, **options)

  File ~/anaconda3/envs/py3_forgeGlmnet/lib/python3.10/site-packages/glmnet_python/glmnet.py:454 in glmnet
    fit = lognet(x, is_sparse, irs, pcs, y, weights, offset, parm,

  File ~/anaconda3/envs/py3_forgeGlmnet/lib/python3.10/site-packages/glmnet_python/lognet.py:41 in lognet
    y = y[:, [1, 0]]

IndexError: index 1 is out of bounds for axis 1 with size 1

This is weird because y(the response) is a 1D array containing 1 and 0, while x is supposed to the 2D array of observations. It was working fine before. I don't remember the version of glmnet_py at that time though. I currently use glmnet from conda-forge, (glmnet_py 1.0.2 py310h89d7329_5 conda-forge) on Mac OS 10.15.7, python 3.10.14.

Did this happen to anyone else ?

thanks you for your help