-
-
Notifications
You must be signed in to change notification settings - Fork 26.2k
Closed
Labels
Description
Describe the bug
KernelPCA.inverse_transform
gives back a zero-meaned dataset, even if the data used to fit the PCA did not have zero mean.
Steps/Code to Reproduce
Example:
from sklearn.datasets import make_blobs
from sklearn.decomposition import KernelPCA
X, _ = make_blobs(n_samples=100, centers=[[1, 1]], random_state=0)
kp = KernelPCA(n_components=2, fit_inverse_transform=True)
X_trans = kp.fit_transform(X)
X_inv = kp.inverse_transform(X_trans)
print(X.mean(axis=0))
print(X_inv.mean(axis=0))
Expected Results
[0.99904232 1.14277867]
[0.99904232 1.14277867]
The mean of the data after transforming and then inverse transforming should be the same, or at least very similar (maybe there are rounding errors etc.) to the mean of the original dataset.
Actual Results
[0.99904232 1.14277867]
[-5.07371922e-16 2.21767049e-16]
(The inverse transformed data still has zero mean)
Versions
System:
python: 3.6.8 (default, Oct 7 2019, 12:59:55) [GCC 8.3.0]
executable: /home//.virtualenvs/kernelpca_issue/bin/python3
machine: Linux-4.15.0-88-generic-x86_64-with-Ubuntu-18.04-bionic
Python dependencies:
pip: 20.0.2
setuptools: 45.2.0
sklearn: 0.22.2.post1
numpy: 1.18.1
scipy: 1.4.1
Cython: None
pandas: None
matplotlib: None
joblib: 0.14.1
Built with OpenMP: True