diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 95b6811b..839f2248 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 ------------------ @@ -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 ------------------ diff --git a/src/quantcore/glm/_glm.py b/src/quantcore/glm/_glm.py index 02dc21be..5f2a560b 100644 --- a/src/quantcore/glm/_glm.py +++ b/src/quantcore/glm/_glm.py @@ -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: diff --git a/tests/glm/test_glm.py b/tests/glm/test_glm.py index fd50ac12..0f1f4864 100644 --- a/tests/glm/test_glm.py +++ b/tests/glm/test_glm.py @@ -1624,7 +1624,7 @@ 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) @@ -1632,7 +1632,7 @@ def test_predict_scalar(regression_data, alpha, alpha_index): 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( @@ -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) @@ -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):