bbalasub1 / glmnet_python

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

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() #22

Closed peiyaoli closed 5 years ago

peiyaoli commented 6 years ago

Hi, I tried the cvglmnet() on my laptop but got this error but the glmnet() runs successfully.

Here is my error information:

ValueError Traceback (most recent call last)

in () 1 warnings.filterwarnings('ignore') ----> 2 cvfit = cvglmnet(x=tmp[:,1:], y = tmp[:,0], family='binomial', ptype = 'auc') 3 warnings.filterwarnings('default') ~/anaconda3/lib/python3.6/site-packages/glmnet_python-0.2.0-py3.6.egg/glmnet_python/cvglmnet.py in cvglmnet(x, y, family, ptype, nfolds, foldid, parallel, keep, grouped, **options) 290 cvstuff = cvlognet(cpredmat, options['lambdau'], x, y \ 291 , options['weights'], options['offset'] \ --> 292 , foldid, ptype, grouped, keep) 293 elif cpredmat[0]['class'] == 'multnet': 294 cvstuff = cvmultnet(cpredmat, options['lambdau'], x, y \ ~/anaconda3/lib/python3.6/site-packages/glmnet_python-0.2.0-py3.6.egg/glmnet_python/cvlognet.py in cvlognet(fit, lambdau, x, y, weights, offset, foldid, ptype, grouped, keep) 78 which = foldid == i 79 for j in range(nlams[i]): ---> 80 cvraw[i,j] = auc_mat(y[which,], predmat[which,j], weights[which]) 81 N = scipy.sum(good, axis = 0) 82 sweights = scipy.zeros([nfolds, 1]) ~/anaconda3/lib/python3.6/site-packages/glmnet_python-0.2.0-py3.6.egg/glmnet_python/cvlognet.py in auc_mat(y, prob, weights) 137 #========================= 138 def auc_mat(y, prob, weights = None): --> 139 if weights == None or len(weights) == 0: 140 weights = scipy.ones([y.shape[0], 1]) 141 wweights = weights*y ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
peiyaoli commented 6 years ago

I think the issue comes from ptype setting. In the demo notebook, if I changed the ptype to auc, same error would pop up as well

bbalasub1 commented 5 years ago

I am unable to reproduce this error on Ubuntu 18.04. Closing. Please reopen with specific example if this problem persists.

ssoftcheck commented 3 years ago

This is a coding error. Line 139 in cvlognet.py should be is None, not == None