civisanalytics / python-glmnet

A python port of the glmnet package for fitting generalized linear models via penalized maximum likelihood.
Other
262 stars 59 forks source link

ElasticNet.predict returns 0d array on 1-row inputs #52

Closed stephen-hoover closed 5 years ago

stephen-hoover commented 5 years ago

The glment.ElasticNet.predict method outputs an array with dimension 0 when given one row to predict. It should return an array with dimension 1 and shape (1,). Presumably the LogitNet.predict_proba has the same problem.

Code to reproduce using glmnet v2.0.0:

from sklearn import datasets
X, y = datasets.make_regression(n_samples=9, n_features=4, random_state=0)

import glmnet
print(glmnet.__version__)
gl = glmnet.ElasticNet(random_state=0)
gl.fit(X, y)

print(gl.predict(X[:2], lamb=[20, 10]).shape)
print(gl.predict(X[:1], lamb=[20, 10]).shape)
print(gl.predict(X[:2]).shape)
print(gl.predict(X[:1]).shape)

Actual output:

2.0.0+18.ga25bcef
(2, 2)
(2,)
(2,)
()

Expected output:

2.0.0+18.ga25bcef
(2, 2)
(2,)
(2,)
(1,)

I'd originally reported this under #30 , but I believe it's a different issue.