Skip to content

ENH PLS target values (Y) inverse-transform #19680

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 13 commits into from
Oct 14, 2021

Conversation

robinthibaut
Copy link
Contributor

Reference Issues/PRs

What does this implement/fix? Explain your changes.

I simply added the possibility to inverse transform new target values "Y" in the "inverse_transform" method of "_pls.py" in "cross_decomposition".
Currently, the "inverse_transform" method only support one "X" argument. I constantly have to inverse transform for new target values "Y", so I wish there was a built-in method to do so.

Current implementation:
-> Returns "X_reconstructed"

    def inverse_transform(self, X):
        """Transform data back to its original space.

New implementation (PR) :
-> Returns "X_reconstructed" if "X" given or "Y_reconstructed" if "Y" given.

    def inverse_transform(self, X=None, Y=None):
        """Transform data back to its original space.

This PR is quite trivial, it passed all the tests in "test_pls.py", and I modified the docstring accordingly.
Thanks for considering my PR and adding this "new" feature.

Any other comments?

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 PR @robinthibaut !

This PR still requires test to make sure the new functionality works as intended.

@@ -334,7 +334,7 @@ def transform(self, X, Y=None, copy=True):

return x_scores

def inverse_transform(self, X):
def inverse_transform(self, X=None, Y=None):
Copy link
Member

Choose a reason for hiding this comment

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

In principle, we do not need both inputs here, but making X optional would be a first for scikit-learn. I think we would still need keep X and have Y optional.

This would be similar to how transform works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello, thanks for having a look at this. I do agree with your comment. In my daily workflow, there's a step where I only need to inverse transform for Y, hence my implementation with optional X. However, since the operation is not computationally intensive, your review would solve my issue and better fit within scikit-learn.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @thomasjpfan that it would be more natural to have always X.

Comment on lines 352 to 353
'X_reconstructed' if X given : array-like of shape (n_samples, n_features),
'Y_reconstructed' if Y given : array-like of shape (n_samples, n_features)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'X_reconstructed' if X given : array-like of shape (n_samples, n_features),
'Y_reconstructed' if Y given : array-like of shape (n_samples, n_features)
X_reconstructed : array-like of shape (n_samples, n_features)
Reconstructed data.
Y_reconstructed : array-like of shape (n_samples, n_features) or None
Reconstructed target. Returned only when `Y` is not `None`.

@glemaitre
Copy link
Member

As mentioned by @thomasjpfan, we will need a test to check the behaviour of the new feature.

robinthibaut and others added 2 commits September 27, 2021 11:19
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
@robinthibaut
Copy link
Contributor Author

Greetings, @thomasjpfan and @glemaitre.

I committed the changes you suggested in sklearn/cross decomposition/_pls.py.

As requested, I included a test for the new feature in my most recent commit. All of the previous tests, as well as the new one, were successful.

I'm hoping that this will strengthen this PR and allow it to be merged.

Best,
Robin

@glemaitre
Copy link
Member

@robinthibaut Could you solve the conflict?

@robinthibaut
Copy link
Contributor Author

@glemaitre The conflict has now been resolved.

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.

Please add an entry to the change log at doc/whats_new/v1.1.rst with tag |Enhancement|. Like the other entries there, please reference this pull request with :pr: and credit yourself (and other contributors if applicable) with :user:.

@thomasjpfan thomasjpfan changed the title [MRG] PLS target values (Y) inverse-transform ENH PLS target values (Y) inverse-transform Oct 6, 2021
robinthibaut and others added 3 commits October 7, 2021 10:23
Update docstring for more consistency

Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
@robinthibaut
Copy link
Contributor Author

@thomasjpfan I committed your docstring suggestion and updated the change log.

@thomasjpfan
Copy link
Member

There are linting issues that should be resolved by installing and running black:

pip install black==21.6b0
black .

@robinthibaut
Copy link
Contributor Author

@thomasjpfan It has been completed. I'll be more cautious with the checks the next time I submit a PR.

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.

LGTM

Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
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.

LGTM

@glemaitre glemaitre merged commit 7314691 into scikit-learn:main Oct 14, 2021
@glemaitre
Copy link
Member

Merging Thanks @robinthibaut

@glemaitre glemaitre mentioned this pull request Oct 23, 2021
10 tasks
samronsin pushed a commit to samronsin/scikit-learn that referenced this pull request Nov 30, 2021
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.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.

3 participants