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

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

Open
esantorella opened this issue Mar 6, 2020 · 4 comments

Comments

@esantorella
Copy link

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
Copy link
Author

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
Copy link

githubhnw commented Nov 6, 2020

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
Copy link

DBeZ commented Dec 7, 2020

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

@njeanne
Copy link

njeanne commented Jun 15, 2021

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 :(

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

No branches or pull requests

4 participants