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

Weights Variable Issue #19

Open
mzhao94 opened this issue Nov 17, 2017 · 0 comments
Open

Weights Variable Issue #19

mzhao94 opened this issue Nov 17, 2017 · 0 comments

Comments

@mzhao94
Copy link

mzhao94 commented Nov 17, 2017

I'm having an issue with using sample weights when trying to run multinomial lasso using the glmnet() function. I get this error:
Traceback (most recent call last):
File "lasso.py", line 37, in
fit = glmnet(x=sparse_matrix.copy(), y=y_float.copy(), family='multinomial', weights=sweights_float)
File "/home/mzhao94/.local/lib/python3.5/site-packages/glmnet_python/glmnet.py", line 455, in glmnet
thresh, isd, intr, maxit, kopt, family)
File "/home/mzhao94/.local/lib/python3.5/site-packages/glmnet_python/lognet.py", line 60, in lognet
y = y*scipy.tile(weights, (1, ny))
ValueError: operands could not be broadcast together with shapes (190349,3) (1,571047)

I've verified that the "x" dataset's dimensions are (190349, 12249) and the "y" and "weights" arrays are both (190349, 1). I'm not sure why I'm getting this ValueError. Does the "weights" array need to have different specific dimensions? I seem to have no issues when I don't use the weights argument.

Here is the core part of my code:

`id_weight_y = pd.read_csv('resp_weights.csv')
ind_vars = pd.read_csv('dummies_ixns.csv')
ind_vars = ind_vars.drop(["employed", "pubhous", "fvehicle"], axis=1)

ids = id_weight_y["unique_id"].as_matrix()
y = id_weight_y["neverNewOldStmp"].as_matrix()
y_float = y.astype(scipy.float64)
sweights = id_weight_y["idvdwt_crsec_coreimgrt"].as_matrix()
sweights_float = sweights.astype(scipy.float64)

sparse_matrix = scipy.sparse.csc_matrix(ind_vars, dtype=scipy.float64)
#print(sparse_matrix)

startTime = time.time()

fit = glmnet(x=sparse_matrix.copy(), y=y_float.copy(), family='multinomial', weights=sweights_float)

print ('The script took {0} second !'.format(time.time() - startTime))

`

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

1 participant