You can do
proj = pca.inverse_transform(X_train_pca)
Thus, you do not need to worry about how to do the multiplication.
After pca.fit_transform or pca.transform you get pca.fit_transform , which is usually called "loads" for each sample, which means how much volume of each component you need to describe best using a linear combination of components_ (principal axes in the feature space).) .
The projection you are aiming at returns to the original signal space. This means that you need to return to the signal space using components and loads.
So there are three steps to disambiguating here. Here you have, step by step, what you can do with the PCA and how it is actually calculated:
pca.fit evaluates components (using SVD on a centered Xtrain):
from sklearn.decomposition import PCA import numpy as np from numpy.testing import assert_array_almost_equal
pca.transform calculates loads as you describe
X_train_pca = pca.transform(X_train) X_train_pca2 = (X_train - pca.mean_).dot(pca.components_.T) assert_array_almost_equal(X_train_pca, X_train_pca2)
pca.inverse_transform gets the projection onto the components in the signal space you are interested in
X_projected = pca.inverse_transform(X_train_pca) X_projected2 = X_train_pca.dot(pca.components_) + pca.mean_ assert_array_almost_equal(X_projected, X_projected2)
Now you can estimate the loss of forecast
loss = ((X_train - X_projected) ** 2).mean()
source share