glm-tools / pyglmnet

Python implementation of elastic-net regularized generalized linear models
http://glm-tools.github.io/pyglmnet/
MIT License
280 stars 84 forks source link

Handling sparse matrices #229

Closed sjkoelle closed 4 months ago

sjkoelle commented 6 years ago

Hi,

I am trying to run a linear model with group lasso regularization and sparse matrix input.

code (x is a sparse matrix, y a vector):

glm = GLM(distr='normal',group = groups) glm.fit(x, y)

However, I get the following error.

output: ValueError Traceback (most recent call last)

in () 2 glm = GLM(distr='normal',group = groups) ----> 3 glm.fit(x, y) ~/anaconda3/envs/py35021518/lib/python3.5/site-packages/pyglmnet/pyglmnet.py in fit(self, X, y) 579 if not isinstance(X, np.ndarray): 580 raise ValueError('Input data should be of type ndarray (got %s).' --> 581 % type(X)) 582 583 n_features = np.float(X.shape[1]) ValueError: Input data should be of type ndarray (got ). I tried to find your sparse matrix benchmarking data in the package, but was unable to. I also looked into the source code, and am not sure where the sparse matrix compatibility is implemented. Can you point me in the right direction (either to an example which uses sparse matrices, by correcting the error presumably present in my syntax, or telling me how to adjust the source code)? Thanks a lot, Sam
jasmainak commented 6 years ago

Hi Sam, you are correct that sparse matrix compatibility is not implemented yet. This would be a welcome feature though.

pavanramkumar commented 6 years ago

Yes, when the documentation says "sparse matrix", we mean it's a dense matrix with sparse non-zero entries. I realize how this can be confusing.

You are welcome to submit a pull request to handle sparse matrices.

sjkoelle commented 2 years ago

A few years later but saw this was still open - I wrote a tensor version here https://github.com/sjkoelle/montlake/blob/master/montlake/optimization/gradientgrouplasso.py