Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jiwidi
Copy link
Contributor

@jiwidi jiwidi commented Oct 18, 2019

Reference Issues/PRs

What does this implement/fix? Explain your changes.

With this PR I'm adding a function inverse_transform to the base _PLS object and the consecuent test. This function is already implemented in other decomposition methods like PCA here.

The function transforms back to the original space by multiplying the transformed data with the x_loadings as X_original = np.matmul(X, self.x_loadings_.T) and denormalizes the result with the model std and mean.

This function allows you to transform back data to the original space (this transformation will only be exact if n_components=n_features). This transformation is widely used to compute the Squared Prediction Error of our _PLS model. This metric is famous for its use in industry scenarios where PLS acts as a statistical model to control processes where time takes a big act (papers on this: 1, 2 )

Following Sklearn _PLS example this is how the function should be used:

from sklearn.cross_decomposition import PLSRegression
X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]
Y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]
pls2 = PLSRegression(n_components=2)
pls2.fit(X, Y)


t = [0., 0., 1.]
Y_pred = pls2.transform([t])
X_reconstructed = pls2.inverse_transform(Y_pred) # Value will be [0.02257852, 0.11391906, 0.87805722]

And a example to showcase the correctness of the function with n_components==n_features

from sklearn.cross_decomposition import PLSRegression
X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]
Y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]
pls2 = PLSRegression(n_components=3)
pls2.fit(X, Y)


t = [0., 0., 1.]
Y_pred = pls2.transform([t])
X_reconstructed = pls2.inverse_transform(Y_pred) # Value will be [0, 0, 1]

Any other comments?

I have been developing software for multivariate statistical process control for some time now and Sklearn implementation of PLS has been widely used in this field. I always thought the _PLS was lacking from this method while PCA had it and decided to make a contribution for it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant