netneurolab / pypyls

A Python implementation of Partial Least Squares (PLS) decomposition
https://pyls.readthedocs.io
GNU General Public License v2.0
59 stars 29 forks source link

PLSRegression alters input matrices #63

Open mfschmidt opened 1 year ago

mfschmidt commented 1 year ago

First, thank you so much for this repo! Trying to compare results between python and matlab has been an insane headache until I found this. :)

I noticed that every time I run pls_regression(), my X and Y input matrices both get altered. To prevent this, I am currently creating a sacrificial copy of each original matrix for use with pls_regression, and all's well. But I wanted to report that this surprised me. I would expect that my source data not be altered.

I assume this could be fixed by creating local copies of X and Y_agg prior to https://github.com/netneurolab/pypyls/blob/d8a19d564cc5804249527b68c937df3a5fd8c7cc/pyls/types/regression.py#L395, and using the local copies rather than references to the originals throughout that function, but I'm not familiar enough with the rest of the codebase to say that with confidence.

Best wishes!

LuuuXG commented 1 month ago

I also found this issue. Unfortunately, the author team doesn't seem to have fixed it. Interestingly, if the matrix is z-score transformed beforehand, it seems that performing pls_regression() does not change the input matrix.