Skip to content

Commit

Permalink
set alpha=0 as default
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasSchmidtblaicherQC committed Jan 31, 2024
1 parent 6816dad commit 9603387
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 63 deletions.
20 changes: 10 additions & 10 deletions src/glum/_glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ def _set_up_for_fit(self, y: np.ndarray) -> None:
elif (self.lower_bounds is None) and (self.upper_bounds is None):
if np.all(np.asarray(self.l1_ratio) == 0):
self._solver = "irls-ls"
elif getattr(self, "alpha", 1) == 0 and not self.alpha_search:
elif getattr(self, "alpha", 0) == 0 and not self.alpha_search:
self._solver = "irls-ls"
else:
self._solver = "irls-cd"
Expand Down Expand Up @@ -2304,8 +2304,7 @@ def covariance_matrix(
_expected_information = expected_information

if (
(hasattr(self, "alpha") and self.alpha is None)
or (
(
hasattr(self, "alpha")
and isinstance(self.alpha, (int, float))
and self.alpha > 0
Expand Down Expand Up @@ -2914,11 +2913,11 @@ class GeneralizedLinearRegressor(GeneralizedLinearRegressorBase):
alpha : {float, array-like}, optional (default=None)
Constant that multiplies the penalty terms and thus determines the
regularization strength. If ``alpha_search`` is ``False`` (the default),
then ``alpha`` must be a scalar or None (equivalent to ``alpha=1.0``).
then ``alpha`` must be a scalar or None (equivalent to ``alpha=0``).
If ``alpha_search`` is ``True``, then ``alpha`` must be an iterable or
``None``. See ``alpha_search`` to find how the regularization path is
set if ``alpha`` is ``None``. See the notes for the exact mathematical
meaning of this parameter. ``alpha = 0`` is equivalent to unpenalized
meaning of this parameter. ``alpha=0`` is equivalent to unpenalized
GLMs. In this case, the design matrix ``X`` must have full column rank
(no collinearities).
Expand Down Expand Up @@ -3146,10 +3145,11 @@ class GeneralizedLinearRegressor(GeneralizedLinearRegressorBase):
drop_first : bool, optional (default = False)
If ``True``, drop the first column when encoding categorical variables.
Set this to True when alpha=0 and solver='auto' to prevent an error due to a
singular feature matrix. In the case of using a formula with interactions,
setting this argument to ``True`` ensures structural full-rankness (it is
equivalent to ``ensure_full_rank`` in formulaic and tabmat).
Set this to True when ``alpha=0`` and ``solver='auto'`` to prevent an error
due to a singular feature matrix. In the case of using a formula with
interactions, setting this argument to ``True`` ensures structural
full-rankness (it is equivalent to ``ensure_full_rank`` in formulaic and
tabmat).
robust : bool, optional (default = False)
If true, then robust standard errors are computed by default.
Expand Down Expand Up @@ -3573,7 +3573,7 @@ def fit(
self.coef_ = self.coef_path_[-1]
else:
if self.alpha is None:
_alpha = 1.0
_alpha = 0.0
else:
_alpha = self.alpha
if _alpha > 0 and self.l1_ratio > 0 and self._solver != "irls-cd":
Expand Down
6 changes: 0 additions & 6 deletions tests/glm/test_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ def test_poisson_deviance_dispersion_loglihood(weighted):
# logLik(glm_model) # -7.390977 (df=1)

regressor = GeneralizedLinearRegressor(
alpha=0,
family="poisson",
fit_intercept=False,
gradient_tol=1e-8,
Expand Down Expand Up @@ -345,7 +344,6 @@ def test_gamma_deviance_dispersion_loglihood(weighted):
# logLik(glm_model) # -7.057068 (df=2)

regressor = GeneralizedLinearRegressor(
alpha=0,
family="gamma",
fit_intercept=False,
gradient_tol=1e-8,
Expand Down Expand Up @@ -393,7 +391,6 @@ def test_gaussian_deviance_dispersion_loglihood(family, weighted):
# logLik(glm_model) # -7.863404 (df=2)

regressor = GeneralizedLinearRegressor(
alpha=0,
family=family,
fit_intercept=False,
gradient_tol=1e-8,
Expand Down Expand Up @@ -441,7 +438,6 @@ def test_tweedie_deviance_dispersion_loglihood(weighted):
# logLiktweedie(glm_model) # -8.35485

regressor = GeneralizedLinearRegressor(
alpha=0,
family=TweedieDistribution(1.5),
fit_intercept=False,
gradient_tol=1e-8,
Expand Down Expand Up @@ -490,7 +486,6 @@ def test_binomial_deviance_dispersion_loglihood(weighted):
# logLik(glm_model) # -3.365058 (df=1)

regressor = GeneralizedLinearRegressor(
alpha=0,
family="binomial",
fit_intercept=False,
gradient_tol=1e-8,
Expand Down Expand Up @@ -535,7 +530,6 @@ def test_negative_binomial_deviance_dispersion_loglihood(weighted):
# logLik(glm_model) # -4.187887 (df=1)

regressor = GeneralizedLinearRegressor(
alpha=0,
family="negative.binomial",
fit_intercept=False,
gradient_tol=1e-8,
Expand Down
Loading

0 comments on commit 9603387

Please sign in to comment.