PCA 和 SVD
先講結論
在統計上我們有 n 個變數構成的矩陣 B = [v1, v2. .... vn]^T
對 B 做 PCA 得到 eigenvector X
就等於直接對 B 做 SVD 得到的 right singular vectors V
PCA = principal value decomposition
SVD = singular value decomposition
[Proof]
PCA on B = eigen value decomposition on S = B^T*B => find X, Λ , s.t. S = XΛX^-1
X is the eigen vector; diagonal elements of Λ is the eigen values.
SVD on B => find U, Σ, V, s.t. B = UΣV^T
U is the left singular matrix; Σ is the singular values; V is the right singular matrix
B^T*B = VΣU^T*UΣV^T
在統計上我們有 n 個變數構成的矩陣 B = [v1, v2. .... vn]^T
對 B 做 PCA 得到 eigenvector X
就等於直接對 B 做 SVD 得到的 right singular vectors V
PCA = principal value decomposition
SVD = singular value decomposition
[Proof]
PCA on B = eigen value decomposition on S = B^T*B => find X, Λ , s.t. S = XΛX^-1
X is the eigen vector; diagonal elements of Λ is the eigen values.
SVD on B => find U, Σ, V, s.t. B = UΣV^T
U is the left singular matrix; Σ is the singular values; V is the right singular matrix
B^T*B = VΣU^T*UΣV^T
since U^T*U=I
BB^T = VΣV^T
因此
X = V
另外, 主成份(Principal vectors)
P = B*
=====================
每次都要從頭想一次,乾脆寫起來~
【參考資料】
線代啟示錄對SVD本身有很好的解釋, 有圖解!!!
https://ccjou.wordpress.com/2009/09/01/%E5%A5%87%E7%95%B0%E5%80%BC%E5%88%86%E8%A7%A3-svd/
對於EVD (eigenvalue decomposition)、PCA、SVD 三者的關係的說明
https://molecular-service-science.com/2014/07/16/eigen-value-singular-value-decomposition-principal-component-analysis/
下面是抄來的
============== 補充: Matlab 驗證 ===============
假設 mean12L_p 是一個 500*8 的矩陣
[U,S,V] = svd(mean12L_p(:,[7:12 1 2]));
ECGv = U*S;
[~,V_order] = sort(diag(V),'descend');
V = V(:,V_order);
mean8L = mean12L_p(:,[7:12 1 2]);
corV = mean8L'*mean8L;
[vec,val] = eig(corV);
[~,val_order] = sort(diag(val),'descend');
vec = vec(:,val_order);
vec - V_order;
就會是一個零矩陣
BB^T = VΣV^T
因此
X = V
另外, 主成份(Principal vectors)
P = B*
=====================
每次都要從頭想一次,乾脆寫起來~
【參考資料】
線代啟示錄對SVD本身有很好的解釋, 有圖解!!!
https://ccjou.wordpress.com/2009/09/01/%E5%A5%87%E7%95%B0%E5%80%BC%E5%88%86%E8%A7%A3-svd/
對於EVD (eigenvalue decomposition)、PCA、SVD 三者的關係的說明
https://molecular-service-science.com/2014/07/16/eigen-value-singular-value-decomposition-principal-component-analysis/
下面是抄來的
雖然兩者形式十分類似,但從空間運用來看卻有很大不同,前 University of Michigan / Stanford University 的數學教授 Cleve Moler 在他的教科書上是這麼說的:
"Eigenvalues play an important role in situations where the matrix is a transformation from one vector space onto itself."
"Singular values play an important role where the matrix is a transformation from one vector space to a different vector space, possibly with a different dimension."
============== 補充: Matlab 驗證 ===============
假設 mean12L_p 是一個 500*8 的矩陣
[U,S,V] = svd(mean12L_p(:,[7:12 1 2]));
ECGv = U*S;
[~,V_order] = sort(diag(V),'descend');
V = V(:,V_order);
mean8L = mean12L_p(:,[7:12 1 2]);
corV = mean8L'*mean8L;
[vec,val] = eig(corV);
[~,val_order] = sort(diag(val),'descend');
vec = vec(:,val_order);
vec - V_order;
就會是一個零矩陣
留言
張貼留言