Skip to content

FIX Add check array for empirical_covariance #26108

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 7 commits into from
May 23, 2023

Conversation

qbarthelemy
Copy link
Contributor

@qbarthelemy qbarthelemy commented Apr 5, 2023

Reference Issues/PRs

Fixes #25519

What does this implement/fix? Explain your changes.

It adds check_array to empirical_covariance.

Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @qbarthelemy. We don't need it for _oas because it's a private function only called by OAS which already validates X.

Co-authored-by: Jérémie du Boisberranger <34657725+jeremiedbb@users.noreply.github.com>
@qbarthelemy qbarthelemy changed the title FIX Add check array for empirical_covariance and _oas FIX Add check array for empirical_covariance Apr 6, 2023
Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

Thinking about that again, I think it deserves an entry in the changelog. Please add an entry in v1.3.rst, saying that now empirical_covariance gives an informative error message when input is not appropriate.

qbarthelemy and others added 2 commits April 7, 2023 16:36
Co-authored-by: Jérémie du Boisberranger <34657725+jeremiedbb@users.noreply.github.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.

Than you for the PR!

@qbarthelemy qbarthelemy force-pushed the covariance_ecm_checkarray branch from 354b832 to f75cb70 Compare May 1, 2023 14:34
qbarthelemy and others added 2 commits May 1, 2023 16:35
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.

Thank you for the update! LGTM

@@ -84,7 +84,7 @@ def empirical_covariance(X, *, assume_centered=False):
[0.25, 0.25, 0.25],
[0.25, 0.25, 0.25]])
"""
X = np.asarray(X)
X = check_array(X, ensure_2d=False, force_all_finite=False)
Copy link
Member

Choose a reason for hiding this comment

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

For reviewers, I think it's okay to set force_all_finite=False here, which is consistent with the behavior on main. If we set force_all_finite=True, then there can be a performance regression when empirical_covariance is called. The alternative is to set config_context(assume_finite=True) everywhere, but it adds the context manager to many places.

Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @qbarthelemy

@jeremiedbb jeremiedbb enabled auto-merge (squash) May 23, 2023 12:38
@jeremiedbb jeremiedbb merged commit f034f57 into scikit-learn:main May 23, 2023
@qbarthelemy qbarthelemy deleted the covariance_ecm_checkarray branch May 23, 2023 14:02
REDVM pushed a commit to REDVM/scikit-learn that referenced this pull request Nov 16, 2023
Co-authored-by: Jérémie du Boisberranger <34657725+jeremiedbb@users.noreply.github.com>
Co-authored-by: Thomas J. Fan <thomasjpfan@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.

empirical_covariance silently returns invalid results on inputs with a complex dtype
3 participants