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

MNT Use check_scalar in AdaBoostClassifier #21442

Merged

Conversation

genvalen
Copy link
Contributor

@genvalen genvalen commented Oct 24, 2021

Reference Issues/PRs

Addresses #20724
#DataUmbrella

What does this implement/fix? Explain your changes.

Summary of changes to AdaBoostClassifier:

  • Add tests to ensure appropriate behavior when invalid arguments are passed in.
  • Use the helper function check_scalar from sklearn.utils to validate the scalar parameters.

Progress:

  • Add tests
  • Check scalar parameters with helper function

References
1. docs
2. PR #20723

Any other comments?

I am new to these tests. Please make any suggestions. Thank you!

@genvalen genvalen changed the title [WIP] MNT Use check_scalar in AffinityPropagation [WIP] MNT Use check_scalar in AdaBoostClassifier_ Oct 24, 2021
@genvalen genvalen changed the title [WIP] MNT Use check_scalar in AdaBoostClassifier_ [WIP] MNT Use check_scalar in AdaBoostClassifier Oct 24, 2021
@reshamas
Copy link
Member

#DataUmbrella sprint

Comment on lines 560 to 563
def test_adaboost_classifier_params_validation(params, err_type, err_msg):
"""Check the parameters validation in `AdaBoostClassifier`."""
with pytest.raises(err_type, match=err_msg):
AdaBoostClassifier(**params).fit(X, y_class) # args are from toy sample
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @glemaitre, is it appropriate to test the estimator using the toy sample?
(lines 34-40)

# Toy sample
X = [[-2, -1], [-1, -1], [-1, -2], [1, 1], [1, 2], [2, 1]]
y_class = ["foo", "foo", "foo", 1, 1, 1]  # test string class labels
y_regr = [-1, -1, -1, 1, 1, 1]
T = [[-1, -1], [2, 2], [3, 2]]
y_t_class = ["foo", 1, 1]
y_t_regr = [-1, 1, 1]

Would you prefer if I generate different testing data?

Copy link
Contributor Author

@genvalen genvalen Oct 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is marked as outdated, but I didn't make any changes to these lines yet

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is quite common. We should probably move those into a pytest.fixture for the full module to make it more explicit but I don't think you need to do that in this PR (it would be an effort for all test files).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! That's good to know, thank you.

@genvalen genvalen changed the title [WIP] MNT Use check_scalar in AdaBoostClassifier Use check_scalar in AdaBoostClassifier Oct 26, 2021
sklearn/ensemble/_weight_boosting.py Outdated Show resolved Hide resolved
sklearn/ensemble/_weight_boosting.py Outdated Show resolved Hide resolved
sklearn/ensemble/_weight_boosting.py Outdated Show resolved Hide resolved
genvalen and others added 3 commits October 29, 2021 12:09
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

sklearn/ensemble/_weight_boosting.py Outdated Show resolved Hide resolved
@glemaitre glemaitre changed the title Use check_scalar in AdaBoostClassifier NT Use check_scalar in AdaBoostClassifier Oct 30, 2021
@glemaitre glemaitre changed the title NT Use check_scalar in AdaBoostClassifier MNT Use check_scalar in AdaBoostClassifier Oct 30, 2021
Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, it should be fine.

genvalen and others added 3 commits October 30, 2021 17:46
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
@glemaitre glemaitre merged commit 7b6617b into scikit-learn:main Nov 2, 2021
@glemaitre
Copy link
Member

Thanks @genvalen it looks good.

@genvalen
Copy link
Contributor Author

genvalen commented Nov 6, 2021

Thank you for the feedback. :)

@genvalen genvalen deleted the AdaBoostClassifier_add_check_scaler branch November 6, 2021 01:05
samronsin pushed a commit to samronsin/scikit-learn that referenced this pull request Nov 30, 2021
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
mathijs02 pushed a commit to mathijs02/scikit-learn that referenced this pull request Dec 27, 2022
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants