bbalasub1 / glmnet_python

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

TypeError: 'numpy.float64' object cannot be interpreted as an integer in cvglmnet #20

Closed pancodia closed 6 years ago

pancodia commented 6 years ago

While reproducing the example

warnings.filterwarnings('ignore')
cvfit = cvglmnet(x = x.copy(), y = y.copy(), family = 'binomial', ptype = 'class')
warnings.filterwarnings('default')

in the following notebook

https://github.com/bbalasub1/glmnet_python/blob/master/test/glmnet_examples.ipynb

I ran into the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-83-854b5ca47c02> in <module>()
      1 import scipy
      2 warnings.filterwarnings('ignore')
----> 3 cvfit = cvglmnet(x = x.copy(), y = y.copy(), family = 'binomial', ptype = 'class')
      4 warnings.filterwarnings('default')

/data/rqd/cecl/users/panc/local/anaconda3/lib/python3.6/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))
    262         mb = scipy.reshape(mb, [1, mb.size])

/data/rqd/cecl/users/panc/local/anaconda3/lib/python3.6/site-packages/numpy/lib/shape_base.py in tile(A, reps)
    912                 c = c.reshape(-1, n).repeat(nrep, 0)
    913             n //= dim_in
--> 914     return c.reshape(shape_out)

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

It seems that in ˋma = scipy.tile(scipy.arange(nfolds), [1, scipy.floor(nobs/nfolds)])ˋ, ˋ scipy.floor(nobs/nfolds)ˋ should be cast to integer.

pancodia commented 6 years ago

I found in the master branch, this is fixed. I installed the package via ˋpip install glmnet_pyˋ, I guess the pypi package is not updated with the latest master branch.

bbalasub1 commented 6 years ago

Thanks Pan. I will update soon.

On Wed, Dec 27, 2017 at 9:23 PM, Pan Chao notifications@github.com wrote:

I found in the master branch, this is fixed. I installed the package via ˋpip install glmnet_pyˋ, I guess the pypi package is not updated with the latest master branch.

— 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/20#issuecomment-354215896, or mute the thread https://github.com/notifications/unsubscribe-auth/AKpDE_r4Uwx3FNclf1vKxQOj4NKkr-Isks5tEvu7gaJpZM4RN2Ho .

peiyaoli commented 6 years ago

hmmm, same thing happens here

Visdoom commented 6 years ago

Had the same issue. Resolved it by giving it foldids.

raimishah commented 6 years ago

how fix pls

Visdoom commented 6 years ago

@raimishah

You can compile it from source into you python dist-package folder.

git clone https://github.com/bbalasub1/glmnet_python.git
cd glmnet_python
python setup.py install

Then it is fixed.

kingledion commented 6 years ago

For anyone else compiling from source, just a helpful reminder that the python setup.py install will install python2 while python3 setup.py install will install for python3.

michaelcoconnor commented 6 years ago

I just now confirmed that pip install glmnet_py loads a cvglmnet.py file with a scipy.floor(nobs/nfolds) argument in line 260, whereas in the master (at line 261) it is int(scipy.floor(nobs/nfolds)). So it seems that the pypi package has yet to be updated. The pip version did cause the error when I ran the sample code.

dcevid commented 4 years ago

I am getting a similar issue regardless of whether I install the package using pip or from the source. I tried running it on my MacOS and remotely on a linux machine and I am getting the same error. I also tried manually editing the code and cast the scipy.floor(nobs/nfolds) to an integer, but this did not help either. The traceback is:

----> 2 cvglmnet(x=dset['X'], y=dset['Y'])

~/.local/lib64/python3.6/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)) 262 mb = scipy.reshape(mb, [1, mb.size])

/cluster/apps/python/3.6.1/x86_64/lib64/python3.6/site-packages/numpy/lib/shape_base.py in tile(A, reps) 912 c = c.reshape(-1, n).repeat(nrep, 0) 913 n //= dim_in --> 914 return c.reshape(shape_out)

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