如何在没有一个分量的情况下反演PCA?

问题描述 投票:0回答:1

我想通过应用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?

python scikit-learn pca
1个回答
0
投票

为了去除噪声,首先对一些分量进行PCA拟合(pca = PCA(n_components=2)). 然后,查看特征值,识别出属于噪声的分量。

识别出这些噪声分量后(写这个做),对整个数据集进行变换。

例子。

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]
© www.soinside.com 2019 - 2024. All rights reserved.