Skip to content

Add input validation to _basePCA.inverse_transform #29310

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 16 commits into from
Jul 25, 2025

Conversation

icfaust
Copy link
Contributor

@icfaust icfaust commented Jun 20, 2024

This PR does input checking for PCA's inverse_transform method. If the input array doesn't have the proper number of components, and generic numpy/array_api error is thrown for the dot product for mismatched indices. A check_is_fitted is also added (as is necessary). After this addition, the extracts the necessary checks from self._validate_data, and applies them for the components instead of the features. The check for array namespace is expanded to follow the convention in PCA.transform.

Have added a supporting test.

Copy link

github-actions bot commented Jun 20, 2024

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 781ae73. Link to the linter CI: here

@icfaust icfaust changed the title Add input checks to PCA.inverse_transform Add input validation to PCA.inverse_transform Jun 20, 2024
@icfaust icfaust changed the title Add input validation to PCA.inverse_transform Add input validation to _basePCA.inverse_transform Jun 20, 2024
@icfaust icfaust marked this pull request as draft June 20, 2024 12:38
@icfaust icfaust changed the title Add input validation to _basePCA.inverse_transform [WIP] Add input validation to _basePCA.inverse_transform Jun 20, 2024
@icfaust icfaust changed the title [WIP] Add input validation to _basePCA.inverse_transform Add input validation to _basePCA.inverse_transform Jun 21, 2024
@icfaust icfaust marked this pull request as ready for review June 21, 2024 14:27
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 @icfaust.

I simplified the validation to only rely on check_array, which deals with empty input.
If the number of components doesn't match, the following operations will fail. With a not as informative error message though, but good enough. I agree that we could have better error messages in that case, but we need to think about it for all estimators, so I leave that for a future issue/PR.

LGTM.

@jeremiedbb jeremiedbb enabled auto-merge (squash) July 25, 2025 17:22
@icfaust
Copy link
Contributor Author

icfaust commented Jul 25, 2025

@jeremiedbb hey thanks for getting it ready to go!

@jeremiedbb jeremiedbb merged commit c84c33e into scikit-learn:main Jul 25, 2025
36 checks passed
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.

2 participants