bbalasub1 / glmnet_python

GNU General Public License v3.0
200 stars 95 forks source link

Simple cvglment example fails due to using float when int is required #46

Open esantorella opened 4 years ago

esantorella commented 4 years ago

I ran the following code:

import numpy as np
from glmnet_py import cvglmnet

n_rows = 1000
np.random.seed(0)

cvglmnet(
    x=np.random.random((n_rows, 2)),
    y=np.random.random(n_rows)
)

I get the following error:

  File "tests/cvglmnet_fold_bug_reproducible.py", line 9, in <module>
    y=np.random.random(n_rows)
  File "/pyenv/versions/elasticity_estimation/lib/python3.7/site-packages/glmnet_py/cvglmnet.py", line 260, in cvglmnet
    ma = scipy.tile(scipy.arange(nfolds), [1, scipy.floor(nobs/nfolds)])
  File "<__array_function__ internals>", line 6, in tile
  File "/pyenv/versions/elasticity_estimation/lib/python3.7/site-packages/numpy/lib/shape_base.py", line 1244, in tile
    return c.reshape(shape_out)
TypeError: 'numpy.float64' object cannot be interpreted as an integer

I believe this can be corrected by changing line 260 of cvglmnet to ma = scipy.tile(scipy.arange(nfolds), [1, nobs // nfolds]).

I will submit a pull request if you agree.

esantorella commented 4 years ago

Actually, I believe this has already been fixed in the version of the code on github. The version on Pypy needs to be updated.

githubhnw commented 4 years ago

Hi, although the line in cvglmnet.py has changed it gives me the same error: image

as if the line is not changed.

How can I overcome this issue? I've also downgraded numpy version from 1.19 to 1.17.5.

For now I 'solved' it by setting foldid parameter to:

foldid = scipy.random.choice(10, size = y_train.shape[0], replace = True)

For a CV=10 Thank you

DBeZ commented 3 years ago

Error is still occurring, indicating installation packages have not been updated yet.

njeanne commented 3 years ago

I pick up on what @DBeZ and @esantorella said, it would be so great if the Pypi repository could be updated. We unfortunately can't use a conda environment with the glmnet_python package :(