[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Consistent loss name for absolute error #19733

Merged
merged 13 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TST nicer deprecation tests
  • Loading branch information
lorentzenchr committed Mar 20, 2021
commit 2e6563488ffba14332585b342a748973e230bc6f
14 changes: 8 additions & 6 deletions sklearn/ensemble/tests/test_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1498,16 +1498,18 @@ def test_n_features_deprecation(Estimator):


# TODO: Remove in v1.2
@pytest.mark.parametrize("criterion", ["mse", "mae"])
def test_criterion_deprecated(criterion):
est1 = RandomForestRegressor(criterion=criterion, random_state=0)
@pytest.mark.parametrize("old_criterion, new_criterion", [
("mse", "squared_error"),
("mae", "absolute_error"),
])
def test_criterion_deprecated(old_criterion, new_criterion):
est1 = RandomForestRegressor(criterion=old_criterion, random_state=0)

with pytest.warns(FutureWarning,
match="Criterion '" + criterion + "' was deprecated"):
match=f"Criterion '{old_criterion}' was deprecated"):
est1.fit(X, y)

d = {"mse": "squared_error", "mae": "absolute_error"}
est2 = RandomForestRegressor(criterion=d[criterion], random_state=0)
est2 = RandomForestRegressor(criterion=new_criterion, random_state=0)
est2.fit(X, y)
assert_allclose(est1.predict(X), est2.predict(X))

Expand Down
14 changes: 8 additions & 6 deletions sklearn/ensemble/tests/test_gradient_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1390,15 +1390,17 @@ def test_criterion_mse_deprecated(Estimator):


# TODO: Remove in v1.2
@pytest.mark.parametrize("loss", ["ls", "lad"])
def test_loss_deprecated(loss):
est1 = GradientBoostingRegressor(loss=loss, random_state=0)
@pytest.mark.parametrize("old_loss, new_loss", [
("ls", "squared_error"),
("lad", "absolute_error"),
])
def test_loss_deprecated(old_loss, new_loss):
est1 = GradientBoostingRegressor(loss=old_loss, random_state=0)

with pytest.warns(FutureWarning,
match="The loss '" + loss + "' was deprecated"):
match=f"The loss '{old_loss}' was deprecated"):
est1.fit(X, y)

d = {"ls": "squared_error", "lad": "absolute_error"}
est2 = GradientBoostingRegressor(loss=d[loss], random_state=0)
est2 = GradientBoostingRegressor(loss=new_loss, random_state=0)
est2.fit(X, y)
assert_allclose(est1.predict(X), est2.predict(X))
14 changes: 8 additions & 6 deletions sklearn/linear_model/tests/test_ransac.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,15 +539,17 @@ def test_ransac_final_model_fit_sample_weight():


# TODO: Remove in v1.2
@pytest.mark.parametrize("loss", ["absolute_loss", "squared_loss"])
def test_loss_deprecated(loss):
est1 = RANSACRegressor(loss=loss, random_state=0)
@pytest.mark.parametrize("old_loss, new_loss", [
("absolute_loss", "squared_error"),
("squared_loss", "absolute_error"),
])
def test_loss_deprecated(old_loss, new_loss):
est1 = RANSACRegressor(loss=old_loss, random_state=0)

with pytest.warns(FutureWarning,
match="The loss '" + loss + "' was deprecated"):
match=f"The loss '{old_loss}' was deprecated"):
est1.fit(X, y)

d = {"absolute_loss": "absolute_error", "squared_loss": "squared_error"}
est2 = RANSACRegressor(loss=d[loss], random_state=0)
est2 = RANSACRegressor(loss=new_loss, random_state=0)
est2.fit(X, y)
assert_allclose(est1.predict(X), est2.predict(X))
14 changes: 8 additions & 6 deletions sklearn/tree/tests/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2121,14 +2121,16 @@ def test_X_idx_sorted_deprecated(TreeEstimator):

# TODO: Remove in v1.2
@pytest.mark.parametrize("Tree", REG_TREES.values())
@pytest.mark.parametrize("criterion", ["mse", "mae"])
def test_mse_deprecated(Tree, criterion):
tree = Tree(criterion=criterion)
@pytest.mark.parametrize("old_criterion, new_criterion", [
("mse", "squared_error"),
("mae", "absolute_error"),
])
def test_criterion_deprecated(Tree, old_criterion, new_criterion):
tree = Tree(criterion=old_criterion)

with pytest.warns(FutureWarning,
match="Criterion '" + criterion + "' was deprecated"):
match=f"Criterion '{old_criterion}' was deprecated"):
tree.fit(X, y)

d = {"mse": "squared_error", "mae": "absolute_error"}
tree_new = Tree(criterion=d[criterion]).fit(X, y)
tree_new = Tree(criterion=new_criterion).fit(X, y)
assert_allclose(tree.predict(X), tree_new.predict(X))