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

ValueError: operands could not be broadcast together with shapes (28,2) (1,56) using weights #24

Open
Visdoom opened this issue Mar 15, 2018 · 3 comments

Comments

@Visdoom
Copy link

Visdoom commented Mar 15, 2018

Hey there,

I tried using weights on the samples. However, I run into this error:


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-62-c9638c455afe> in <module>()
     23 
     24     cvfit = cvglmnet(x = X_train.copy(), y = y_train.copy().astype(np.float64),ptype='deviance', nfolds=5,
---> 25                  family = 'binomial', alpha=0.8, weights=weights.copy())
     26 
     27     y_hat =  cvglmnetPredict(cvfit, newx = X_test, s='lambda_min', ptype='class').reshape(-1)

/usr/local/lib/python3.5/dist-packages/glmnet_python/glmnet_python/cvglmnet.py in cvglmnet(x, y, family, ptype, nfolds, foldid, parallel, keep, grouped, **options)
    241 
    242     # main call to glmnet
--> 243     glmfit = glmnet(x = x, y = y, family = family, **options)
    244 
    245     is_offset = glmfit['offset']

/usr/local/lib/python3.5/dist-packages/glmnet_python/glmnet_python/glmnet.py in glmnet(x, y, family, **options)
    453         fit = lognet(x, is_sparse, irs, pcs, y, weights, offset, parm,
    454                      nobs, nvars, jd, vp, cl, ne, nx, nlam, flmin, ulam,
--> 455                      thresh, isd, intr, maxit, kopt, family)
    456     elif family == 'cox':
    457         # call coxnet

/usr/local/lib/python3.5/dist-packages/glmnet_python/glmnet_python/lognet.py in lognet(x, is_sparse, irs, pcs, y, weights, offset, parm, nobs, nvars, jd, vp, cl, ne, nx, nlam, flmin, ulam, thresh, isd, intr, maxit, kopt, family)
     58             mv, ny = y.shape
     59 
---> 60         y = y*scipy.tile(weights, (1, ny))
     61 
     62     #

ValueError: operands could not be broadcast together with shapes (28,2) (1,56) 

seems sth is odd with unpacking the shape of y

@Visdoom
Copy link
Author

Visdoom commented Mar 16, 2018

I realized it is the same issue as #19

@JoeyFaulkner
Copy link

Also having this issue, any info on how to fix this?

@DexGroves
Copy link

Try doing: weights = weights.reshape((len(weights), 1)). It expects weights to have shape (N, 1) (a matrix with one column) rather than shape (N,) (a vector).

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

3 participants