Skip to content

Commit bde883b

Browse files
authored
Honor the offset when alpha is None (#391)
1 parent 6184bb2 commit bde883b

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
Changelog
88
=========
99

10+
1.5.1 - 2021-07-22
11+
------------------
12+
13+
**Bug fix:**
14+
15+
* Have the :meth:`linear_predictor` and :meth:`predict` methods of :class:`~quantcore.glm.GeneralizedLinearRegressor` and :class:`~quantcore.glm.GeneralizedLinearRegressorCV`
16+
honor the offset when ``alpha`` is ``None``.
17+
1018
1.5.0 - 2021-07-15
1119
------------------
1220

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

24-
2532
1.4.3 - 2021-06-25
2633
------------------
2734

src/quantcore/glm/_glm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,8 @@ def linear_predictor(
11581158

11591159
if alpha_index is None:
11601160
xb = X @ self.coef_ + self.intercept_
1161+
if offset is not None:
1162+
xb += offset
11611163
elif np.isscalar(alpha_index): # `None` doesn't qualify
11621164
xb = X @ self.coef_path_[alpha_index] + self.intercept_path_[alpha_index]
11631165
if offset is not None:

tests/glm/test_glm.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,15 +1624,15 @@ def test_alpha_search(regression_data):
16241624
def test_predict_scalar(regression_data, alpha, alpha_index):
16251625

16261626
X, y = regression_data
1627-
offset = np.zeros_like(y)
1627+
offset = np.ones_like(y)
16281628

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

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

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

16371637

16381638
@pytest.mark.parametrize(
@@ -1642,7 +1642,7 @@ def test_predict_scalar(regression_data, alpha, alpha_index):
16421642
def test_predict_list(regression_data, alpha, alpha_index):
16431643

16441644
X, y = regression_data
1645-
offset = np.zeros_like(y)
1645+
offset = np.ones_like(y)
16461646

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

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

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

16641664

16651665
def test_predict_error(regression_data):

0 commit comments

Comments
 (0)