bbalasub1 / glmnet_python

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

Typer error when trying to run cvglmnet #6

Closed YSanchezAraujo closed 5 years ago

YSanchezAraujo commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

Hi,

Thanks! Can you change and do a merge request, and I will pull it into the master?

Bala

On Fri, Apr 14, 2017 at 10:15 PM, Yoel Sanchez Araujo < notifications@github.com> wrote:

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) in ()----> 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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bbalasub1/glmnet_python/issues/6, or mute the thread https://github.com/notifications/unsubscribe-auth/AKpDE49ogcNRmKpeHKt_3bjexz_scUtuks5rwChIgaJpZM4M-OTm .

mzhao94 commented 6 years ago

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

Thanks.

davidarteta commented 5 years ago

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 commented 5 years ago

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 commented 3 years ago

I got the same error on Mac.