8000 [MRG] MNT use check_scalar to validate scalar in SpectralClustering by hvassard · Pull Request #21881 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG] MNT use check_scalar to validate scalar in SpectralClustering #21881

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

Conversation

hvassard
Copy link
Contributor
@hvassard hvassard commented Dec 4, 2021

Reference Issues/PRs
Addresses #20724
#DataUmbrella

What does this implement/fix? Explain your changes.
Summary of changes to SpectralClustering:

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. check_scalar docs
  2. SpectralClustering docs
  3. PR #20723

Any other comments?
This is my very first contibution to an open source project, please do not hesitate to give me a feedback. Thank you!

@hvassard hvassard changed the title [MNT] use check_scalar to validate scalar in SpectralClustering [MRG] MNT use check_scalar to validate scalar in SpectralClustering Dec 4, 2021
Copy link
Member
@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

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

LGTM!

Please document the change in the changelog for 1.1 (in doc/whats_new/v1.1.rst).

@hvassard
Copy link
Contributor Author

Hello @ogrisel ! Thank you for your review, I just updated the changelog.

@hvassard
Copy link
Contributor Author

It looks like there's a bug causing CI to fail (may be fixed in #22049)

Copy link
Member
@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

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

Thank you, @hvassard.

This LGTM after addressing a few suggestions.

hvassard and others added 3 commits January 7, 2022 16:14
Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
@hvassard
Copy link
Contributor Author
hvassard commented Jan 7, 2022

Thank you for your review @jjerphan ! I just updated the code with your suggestions.

Copy link
Member
@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for your responsiveness, @hvassard.

Comment on lines +115 to +149
@pytest.mark.parametrize(
"input, params, err_type, err_msg",
[
(X, {"n_clusters": -1}, ValueError, "n_clusters == -1, must be >= 1"),
(X, {"n_clusters": 0}, ValueError, "n_clusters == 0, must be >= 1"),
(
X,
{"n_clusters": 1.5},
TypeError,
"n_clusters must be an instance of <class 'numbers.Integral'>,"
" not <class 'float'>",
),
(X, {"n_init": -1}, ValueError, "n_init == -1, must be >= 1"),
(X, {"n_init": 0}, ValueError, "n_init == 0, must be >= 1"),
(
X,
{"n_init": 1.5},
TypeError,
"n_init must be an instance of <class 'numbers.Integral'>,"
" not <class 'float'>",
),
(X, {"gamma": -1}, ValueError, "gamma == -1, must be >= 1"),
(X, {"gamma": 0}, ValueError, "gamma == 0, must be >= 1"),
(X, {"n_neighbors": -1}, ValueError, "n_neighbors == -1, must be >= 1"),
(X, {"n_neighbors": 0}, ValueError, "n_neighbors == 0, must be >= 1"),
(
X,
{"eigen_tol": -1, "eigen_solver": "arpack"},
ValueError,
"eigen_tol == -1, must be >= 0",
),
(X, {"degree": -1}, ValueError, "degree == -1, must be >= 1"),
(X, {"degree": 0}, ValueError, "degree == 0, must be >= 1"),
],
)
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for this extensive test!

@jjerphan jjerphan merged commit 26e2c38 into scikit-learn:main Jan 7, 2022
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.

4 participants
0