-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add alpha parameter to
lasso_regression
(#232)
Closes #163. ### Summary of Changes Add alpha parameter to lasso regression --------- Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Co-authored-by: Lars Reimann <mail@larsreimann.com>
- Loading branch information
1 parent
f4f44a6
commit b5050b9
Showing
2 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
tests/safeds/ml/classical/regression/test_lasso_regression.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
from safeds.data.tabular.containers import Table | ||
from safeds.ml.classical.regression import LassoRegression | ||
|
||
|
||
def test_should_throw_value_error() -> None: | ||
with pytest.raises(ValueError, match="alpha must be non-negative"): | ||
LassoRegression(alpha=-1) | ||
|
||
|
||
def test_should_throw_warning() -> None: | ||
with pytest.warns( | ||
UserWarning, | ||
match=( | ||
"Setting alpha to zero makes this model equivalent to LinearRegression. You " | ||
"should use LinearRegression instead for better numerical stability." | ||
), | ||
): | ||
LassoRegression(alpha=0) | ||
|
||
|
||
def test_should_give_alpha_to_sklearn() -> None: | ||
training_set = Table.from_dict({"col1": [1, 2, 3, 4], "col2": [1, 2, 3, 4]}) | ||
tagged_table = training_set.tag_columns("col1") | ||
|
||
regressor = LassoRegression(alpha=1).fit(tagged_table) | ||
assert regressor._wrapped_regressor is not None | ||
assert regressor._wrapped_regressor.alpha == regressor._alpha |