Skip to content

Commit

Permalink
Merge b5a39a3 into 831e2ad
Browse files Browse the repository at this point in the history
  • Loading branch information
guyrt committed Nov 7, 2013
2 parents 831e2ad + b5a39a3 commit 47e3f3d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion statsmodels/discrete/discrete_model.py
Expand Up @@ -669,8 +669,12 @@ def predict(self, params, exog=None, exposure=None, offset=None,
exog = self.exog
offset = getattr(self, 'offset', 0)
exposure = getattr(self, 'exposure', 0)

else:
if isinstance(exog, (list, tuple)):
exog = np.array(exog)
if isinstance(exog, np.ndarray) and len(exog.shape) == 1:
exog = exog.reshape((-1, 1))

if exposure is None:
exposure = 0
else:
Expand Down
13 changes: 13 additions & 0 deletions statsmodels/discrete/tests/test_discrete.py
Expand Up @@ -1234,6 +1234,19 @@ def test_poisson_predict():
pred3 = res.predict(exog, offset=np.log(2), exposure=1)
assert_almost_equal(2*pred1, pred3)


def test_poisson_predict_convert_exog():
#GH: 1032: ensure exog is properly converted.
data = sm.datasets.randhie.load()
exog = sm.add_constant(data.exog, prepend=True)
res = sm.Poisson(data.endog, exog)
test_data = exog[1, :].reshape(-1)
pred1 = res.predict(np.ones(test_data.shape), exog=test_data.tolist())
# Pass 1 d array
pred2 = res.predict(np.ones(test_data.shape), exog=test_data)
assert_almost_equal(pred1, pred2)


def test_poisson_newton():
#GH: 24, Newton doesn't work well sometimes
nobs = 10000
Expand Down

0 comments on commit 47e3f3d

Please sign in to comment.