-
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.
Closes #166. ### Summary of Changes Added parameter `lasso_ratio` to `ElasticNetRegression` and tests for edge cases 0, 1, invalid and default. --------- Co-authored-by: zzril <> Co-authored-by: megalinter-bot <[email protected]>
- Loading branch information
1 parent
3aad07d
commit 4a1a736
Showing
2 changed files
with
58 additions
and
3 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
39 changes: 39 additions & 0 deletions
39
tests/safeds/ml/classical/regression/test_elastic_net_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,39 @@ | ||
import pytest | ||
from safeds.data.tabular.containers import Table | ||
from safeds.ml.classical.regression._elastic_net_regression import ElasticNetRegression | ||
|
||
|
||
def test_lasso_ratio_valid() -> None: | ||
training_set = Table.from_dict({"col1": [1, 2, 3, 4], "col2": [1, 2, 3, 4]}) | ||
tagged_training_set = training_set.tag_columns(target_name="col1", feature_names=["col2"]) | ||
lasso_ratio = 0.3 | ||
|
||
elastic_net_regression = ElasticNetRegression(lasso_ratio).fit(tagged_training_set) | ||
assert elastic_net_regression._wrapped_regressor is not None | ||
assert elastic_net_regression._wrapped_regressor.l1_ratio == lasso_ratio | ||
|
||
|
||
def test_lasso_ratio_invalid() -> None: | ||
with pytest.raises(ValueError, match="lasso_ratio must be between 0 and 1."): | ||
ElasticNetRegression(-1) | ||
|
||
|
||
def test_lasso_ratio_zero() -> None: | ||
with pytest.warns( | ||
UserWarning, | ||
match="ElasticNetRegression with lasso_ratio = 0 is essentially RidgeRegression." | ||
" Use RidgeRegression instead for better numerical stability.", | ||
): | ||
ElasticNetRegression(0) | ||
|
||
|
||
def test_lasso_ratio_one() -> None: | ||
with pytest.warns( | ||
UserWarning, | ||
match="ElasticNetRegression with lasso_ratio = 0 is essentially LassoRegression." | ||
" Use LassoRegression instead for better numerical stability.", | ||
): | ||
ElasticNetRegression(1) | ||
|
||
|
||
# (Default parameter is tested in `test_regressor.py`.) |