如何在没有一个组件的情况下逆向 PCA?

How to inverse PCA without one component?

我想通过应用 PCA 来对信号进行降噪,然后删除一个分量并将 PCA 反演以得到降噪信号。 这是我尝试过的:

reduced = pca.fit_transform(signals)
denoised = np.delete(reduced, 0, 1)
result = pca.inverse_transform(denoised)

但是我有错误:

ValueError: shapes (11,4) and (5,5756928) not aligned: 4 (dim 1) != 5 (dim 0)

如何反转 PCA?

要消除噪声,首先要为多个组件 (pca = PCA(n_components=2)) 拟合 PCA。然后,查看特征值并识别噪声成分。

识别出这些噪声成分后(写这个),转换整个数据集。

示例:

import numpy as np
from sklearn.decomposition import PCA


X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
pca = PCA(n_components=2)
pca.fit(X)

eigenvalues = pca.explained_variance_
print(eigenvalues)
#[7.93954312 0.06045688] # I assume that the 2nd component is noise due to λ=0.06 << 7.93

X_reduced = pca.transform(X)

#Since the 2nd component is considered noise, keep only the projections on the first component
X_reduced_selected = X_reduced[:,0]

并反转使用这个:

pca.inverse_transform(X_reduced)[:,0]