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

2024-05-28 18:23:31 发布

您现在位置:Python中文网/ 问答频道 /正文

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


Tags: 信号nptransformresultdeletefit分量dim
1条回答
网友
1楼 · 发布于 2024-05-28 18:23:31

要去除噪声,首先为许多组件(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]

相关问题 更多 >

    热门问题