假設現在有一個數據矩陣X ,其大小是n×p ,其中 n is the number of samples and p is the number of variables (或features)。這裏,XT 可以寫成{x1,x2,⋯,xn} ,x1 表示一個長度爲p 的列向量,也就是說,XT 包含 n independent observations x1,x2,⋯,xn ,其中每個都是一個 p-dimensional 的列向量,這與【7】中的寫法相一致。
現在,不失普遍性地,讓我們假設X is centered, 即 column means have been subtracted and are now equal to zero。如果X is not centered,也不要緊,我們可以通過計算其與centering matrix H 之間的乘法來對其中心化。H=I−eeT/p , 其中 e is a 每個元素都是1的 column vector。
基於上述條件,可知p×p 大小的協方差矩陣 covariance matrix C 可由 C=XTX/(n−1) 給出。此處,我們稍微補充一下協方差矩陣與相關性矩陣(correlation matrix )的一些內容。如果你對此已經非常瞭解,可以直接跳過這一部分。
如果 X 和 Y 是兩個隨機變量,with means (expected values) μX and μY and standard deviations σX and σY , respectively, then their covariance is
σXY=E[(X−μX)(Y−μY)]
and correlation is:
ρXY=E[(X−μX)(Y−μY)]/(σXσY)
因此
covXY=σXY=ρXYσXσY 。
如果 X are centred data matrices of dimension n×p ,an unbiased estimator of the covariance matrix (sample covariance matrix)
C=1n−1XTX
另一方面,如果 the column means were known a-priori, 則有
C=1nXTX
最後,在MATLAB中計算covariance matrix 和 correlation matrix的方法可以參見【5】。
現在我們知道,C=XTX/(n−1) 是一個對稱矩陣,因此它可以對角化,即
C=VΛVT
其中,
V is a matrix of eigenvectors (each column is an eigenvector) and
Λ is a diagonal matrix with eigenvalues
λi in the decreasing order on the diagonal。
Any matrix has a singular value decomposition, so we have
X=UΣVT
應該注意到
XTX=(UΣVT)T(UΣVT)=VΣTUTUΣVT=V(ΣTΣ)VT
這其實是特徵值分解的結果,我們更進一步,把
C 引入,則有
C=1n−1XTX=1n−1V(ΣTΣ)VT=VΣ2n−1VT
也就是說,Covariance matrix
C 的特徵值
λi 與 矩陣
X 的奇異值
σi 之間的關係是
σ2i=(n−1)λi 。
X 的右singular matrix
V 中的列是與上述主成分相對應的主方向(principal directions)。最後,
XV=UΣVTV=UΣ
則表明,
UΣ 就是主成分(PC)。
參考文獻
【1】https://stats.stackexchange.com/questions/134282/relationship-between-svd-and-pca-how-to-use-svd-to-perform-pca
【2】https://intoli.com/blog/pca-and-svd/
【3】https://en.wikipedia.org/wiki/Estimation_of_covariance_matrices
【4】https://en.wikipedia.org/wiki/Covariance_and_correlation
【5】http://www.mathworks.com/help/stats/corrcov.html?s_tid=gn_loc_drop
【6】http://blog.csdn.net/baimafujinji/article/details/6474273
【7】http://blog.csdn.net/baimafujinji/article/details/79376378