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

Typer error when trying to run cvglmnet #6

Closed
YSanchezAraujo opened this issue Apr 15, 2017 · 6 comments · Fixed by #8
Closed

Typer error when trying to run cvglmnet #6

YSanchezAraujo opened this issue Apr 15, 2017 · 6 comments · Fixed by #8

Comments

@YSanchezAraujo
Copy link

If I create some dummy data:

X = np.random.random((200,10)).astype(scipy.float64)
y = np.zeros(200)
for i in range(0, 200, 2):
    y[i] = 1
y = y.astype(scipy.float64)

then try running cvglment:

fit = cvglmnet(x = X, y = y, family = 'binomial')

I get:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-8dab0d126aa7> in <module>()
----> 1 fit = cvglmnet(x = X, y = y, family = 'binomial')
      2 #scipy.tile(scipy.arange(4), [1, scipy.floor(12/4.)])

/om/user/ysa/miniconda3/envs/py35/lib/python3.5/site-packages/glmnet_python/cvglmnet.py in cvglmnet(x, y, family, ptype, nfolds, foldid, parallel, keep, grouped, **options)
    258 
    259     if len(foldid) == 0:
--> 260         ma = scipy.tile(scipy.arange(nfolds), [1, scipy.floor(nobs/nfolds)])
    261        mb = scipy.arange(scipy.mod(nobs, nfolds))

/om/user/ysa/miniconda3/envs/py35/lib/python3.5/site-packages/numpy/lib/shape_base.py in tile(A, reps)
    878                 c = c.reshape(-1, n).repeat(nrep, 0)
    879             n //= dim_in
--> 880     return c.reshape(shape_out)

TypeError: 'numpy.float64' object cannot be interpreted as an integer

It seems the problem is in the line:

ma = scipy.tile(scipy.arange(nfolds), [1, scipy.floor(nobs/nfolds)])

If instead you change that to:

ma = scipy.tile(scipy.arange(nfolds), [1, int(scipy.floor(nobs/nfolds))])

The problem goes away.

@hanfang
Copy link
Contributor

hanfang commented May 2, 2017

Hi there,
Sorry for the delay. Has been super busy lately. Will find a chance to visit this in about two weeks. Thanks.
Han

@bbalasub1
Copy link
Owner

bbalasub1 commented May 5, 2017 via email

@mzhao94
Copy link

mzhao94 commented Nov 17, 2017

Has this already been pulled into the master branch? I'm getting the same error.

Thanks.

@davidarteta
Copy link

davidarteta commented Feb 14, 2019

I am having same error. Asked about it in Stack overflow:
[https://stackoverflow.com/questions/54671752/why-does-glmnet-py-throw-a-typeerror-at-cvglmnet-when-i-provide-floats-if-glmne]

@bbalasub1 bbalasub1 reopened this Feb 18, 2019
@bbalasub1
Copy link
Owner

This seems to be specific to OS/version. I tried the same problem after a fresh install on Ubuntu/18.04 and could not reproduce it.

@liyi-1989
Copy link

I got the same error on Mac.

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

Successfully merging a pull request may close this issue.

6 participants