理解主成分分析代码的问题

问题描述 投票:0回答:1

任何人都可以解释一下这行代码吗? P =第22行的向量.T.dot(C.T)

我搜索了在线文档,但我一无所获。

from numpy import array
from numpy import mean
from numpy import cov
from numpy.linalg import eig

# define a matrix
A = array([[1, 2], [3, 4], [5, 6]])
print(A)
# calculate the mean of each column
M = mean(A.T, axis=1)
print(M)
# center columns by subtracting column means
C = A - M
print(C)
# calculate covariance matrix of centered matrix
V = cov(C.T)
print(V)
# eigendecomposition of covariance matrix
values, vectors = eig(V)
print(vectors)
print(values)
# project data
P = vectors.T.dot(C.T) # Explain me this line
print(P.T)
numpy pca eigenvalue eigenvector
1个回答
0
投票

vectors.T.dot(C.T)是转置数组vectors与转置数组C的点积

点积运算和投影是相关的,因为当该矢量是单位矢量时,可以使用点积来获得沿着方向(另一矢量)的投影矢量的长度。

由于您的问题相当模糊,我会让您对此答案发表评论并在必要时进行调整。

© www.soinside.com 2019 - 2024. All rights reserved.