Skip to content

Commit

Permalink
Honor the offset when alpha is None (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbittarello authored Jul 22, 2021
1 parent 6184bb2 commit bde883b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
Changelog
=========

1.5.1 - 2021-07-22
------------------

**Bug fix:**

* Have the :meth:`linear_predictor` and :meth:`predict` methods of :class:`~quantcore.glm.GeneralizedLinearRegressor` and :class:`~quantcore.glm.GeneralizedLinearRegressorCV`
honor the offset when ``alpha`` is ``None``.

1.5.0 - 2021-07-15
------------------

Expand All @@ -21,7 +29,6 @@ Changelog
* Don't list ``sparse_dot_mkl`` as a runtime requirement from the conda recipe.
* The minimal ``numpy`` pin should be dependent on the ``numpy`` version in ``host`` and not fixed to ``1.16``.


1.4.3 - 2021-06-25
------------------

Expand Down
2 changes: 2 additions & 0 deletions src/quantcore/glm/_glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,8 @@ def linear_predictor(

if alpha_index is None:
xb = X @ self.coef_ + self.intercept_
if offset is not None:
xb += offset
elif np.isscalar(alpha_index): # `None` doesn't qualify
xb = X @ self.coef_path_[alpha_index] + self.intercept_path_[alpha_index]
if offset is not None:
Expand Down
10 changes: 5 additions & 5 deletions tests/glm/test_glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1624,15 +1624,15 @@ def test_alpha_search(regression_data):
def test_predict_scalar(regression_data, alpha, alpha_index):

X, y = regression_data
offset = np.zeros_like(y)
offset = np.ones_like(y)

estimator = GeneralizedLinearRegressor(alpha=[0.5, 0.75], alpha_search=True)
estimator.fit(X, y)

target = estimator.predict(X, alpha_index=alpha_index)

candidate = estimator.predict(X, alpha=alpha, offset=offset)
np.testing.assert_allclose(candidate, target)
np.testing.assert_allclose(candidate, target + 1)


@pytest.mark.parametrize(
Expand All @@ -1642,7 +1642,7 @@ def test_predict_scalar(regression_data, alpha, alpha_index):
def test_predict_list(regression_data, alpha, alpha_index):

X, y = regression_data
offset = np.zeros_like(y)
offset = np.ones_like(y)

estimator = GeneralizedLinearRegressor(alpha=[0.5, 0.75], alpha_search=True)
estimator.fit(X, y)
Expand All @@ -1656,10 +1656,10 @@ def test_predict_list(regression_data, alpha, alpha_index):
)

candidate = estimator.predict(X, alpha=alpha, offset=offset)
np.testing.assert_allclose(candidate, target)
np.testing.assert_allclose(candidate, target + 1)

candidate = estimator.predict(X, alpha_index=alpha_index, offset=offset)
np.testing.assert_allclose(candidate, target)
np.testing.assert_allclose(candidate, target + 1)


def test_predict_error(regression_data):
Expand Down

0 comments on commit bde883b

Please sign in to comment.