【问题标题】:Why 'pca' in Matlab doesn't give orthogonal principal components?为什么 Matlab 中的“pca”不给出正交主成分?
【发布时间】:2016-05-10 23:31:46
【问题描述】:

为什么在Matlab中使用pca,却无法得到正交主成分矩阵

例如:

A=[3,1,-1;2,4,0;4,-2,-5;11,22,20];

A =

    3     1    -1
    2     4     0
    4    -2    -5
   11    22    20



>> W=pca(A)

W =

    0.2367    0.9481   -0.2125
    0.6731   -0.3177   -0.6678
    0.7006   -0.0150    0.7134


>> PCA=A*W

PCA =

    0.6826    2.5415   -2.0186
    3.1659    0.6252   -3.0962
   -3.9026    4.5028   -3.0812
   31.4249    3.1383   -2.7616

在这里,每一列都是一个主要组件。所以,

>> PCA(:,1)'*PCA(:,2)

ans =

   84.7625

但主成分矩阵没有相互正交的成分。

我检查了一些材料,它说它们不仅不相关,而且严格正交。但我无法得到想要的结果。谁能告诉我哪里出错了?

谢谢!

【问题讨论】:

    标签: matlab pca orthogonal principal-components


    【解决方案1】:

    您对 PCA 特征空间中A 的表示和主成分感到困惑。 W 是主成分,它们确实是正交的。

    检查W(:,1).'*W(:,2) = 5.2040e-17W(:,1).'*W(:,3) = -1.1102e-16——确实是正交的

    尝试要做的是在 PCA 特征空间中转换数据(即A)。您应该首先将数据居中,然后乘以主成分,如下所示。

    % A_PCA = (A-repmat(mean(A),4,1))*W
    % A more efficient alternative to the above command
    A_PCA = bsxfun(@minus,A,mean(A))*W
    % verify that it is correct by comparing it with `score` - i.e. the PCA representation 
    % of A given by MATLAB.
    [W, score] = pca(A); % mean centering will occur inside pca
    (score-(A-repmat(mean(A),4,1))*W) % elements are of the order of 1e-14, hence equal.
    

    【讨论】:

    • 使用bsxfun 比使用repmat 更有效:A_PCA = bsxfun(@minus,A,mean(A))*W
    • 哦,没有平均居中,这就是我错过的!谢谢!
    • 而A在PCA特征空间中的表示,即score也是正交的。
    猜你喜欢
    • 2013-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-03
    • 2015-12-09
    • 2016-01-18
    • 2016-12-11
    相关资源
    最近更新 更多