Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TST Assert error messages for AdaBoost estimators #22144

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

Merged
merged 1 commit into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion sklearn/ensemble/_weight_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ def fit(self, X, y, sample_weight=None):
# Check loss
if self.loss not in ("linear", "square", "exponential"):
raise ValueError(
"loss must be 'linear', 'square', or 'exponential'"
"loss must be 'linear', 'square', or 'exponential'."
f" Got {self.loss!r} instead."
)

Expand Down
13 changes: 9 additions & 4 deletions sklearn/ensemble/tests/test_weight_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy as np
import pytest
import re

from scipy.sparse import csc_matrix
from scipy.sparse import csr_matrix
Expand Down Expand Up @@ -274,15 +275,19 @@ def test_error():
# Test that it gives proper exception on deficient input.

reg = AdaBoostRegressor(loss="foo")
with pytest.raises(ValueError):
msg = "loss must be 'linear', 'square', or 'exponential'. Got 'foo' instead."
with pytest.raises(ValueError, match=msg):
reg.fit(X, y_class)

clf = AdaBoostClassifier(algorithm="foo")
with pytest.raises(ValueError):
msg = "Algorithm must be 'SAMME' or 'SAMME.R'. Got 'foo' instead."
with pytest.raises(ValueError, match=msg):
clf.fit(X, y_class)

with pytest.raises(ValueError):
AdaBoostClassifier().fit(X, y_class, sample_weight=np.asarray([-1]))
clf = AdaBoostClassifier()
msg = re.escape("sample_weight.shape == (1,), expected (6,)")
with pytest.raises(ValueError, match=msg):
clf.fit(X, y_class, sample_weight=np.asarray([-1]))


def test_base_estimator():
Expand Down