【问题标题】:How to inverse PCA without one component?如何在没有一个组件的情况下反转 PCA?
【发布时间】:2023-03-05 15:44:01
【问题描述】:

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

    要消除噪音,首先要为多个组件安装 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]
    

    【讨论】:

    • 我明白了,非常感谢!由于我的数据没有居中,我想我需要将 pca.mean_ 添加到 reduce_denoised 对吗?
    • 是的!你应该重建你的输入数据!
    猜你喜欢
    • 1970-01-01
    • 2017-09-19
    • 2016-07-13
    • 2018-08-22
    • 1970-01-01
    • 2015-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多