pca.inverse_transform in sklearn

haneulkim picture haneulkim · Apr 5, 2019 · Viewed 11k times · Source

after fitting my data into X = my data

pca = PCA(n_components=1)
pca.fit(X)
X_pca = pca.fit_transform(X)

now X_pca has one dimension.

When I perform inverse transformation by definition isn't it supposed to return to original data, that is X, 2-D array?

when I do

X_ori = pca.inverse_transform(X_pca)

I get same dimension however different numbers.

Also if I plot both X and X_ori they are different.

Answer

butterflyknife picture butterflyknife · Apr 5, 2019

When I perform inverse transformation by definition isn't it supposed to return to original data

No, you can only expect this if the number of components you specify is the same as the dimensionality of the input data. For any n_components less than this, you will get different numbers than the original dataset after applying the inverse PCA transformation: the following diagrams give an illustration in two dimensions.

enter image description here