使用np.linalg.svd()查找特征向量和特征值?

时间:2019-02-09 22:52:50

标签: python python-3.x numpy

我试图找到PCA协方差矩阵的特征向量和特征值。

我的代码:

values, vectors = np.linalg.eigh(covariance_matrix)

这是输出:

Eigen Vectors: 
[[ 0.26199559  0.72101681 -0.37231836  0.52237162]
 [-0.12413481 -0.24203288 -0.92555649 -0.26335492]
 [-0.80115427 -0.14089226 -0.02109478  0.58125401]
 [ 0.52354627 -0.6338014  -0.06541577  0.56561105]]

Eigen Values: 
[0.02074601 0.14834223 0.92740362 2.93035378]

然后我发现np.linalg.svd()也返回相同的内容。

U, S, V = np.linalg.svd(standardized_x.T)
print(U)
print(S)
print(V)
[[-0.52237162 -0.37231836  0.72101681  0.26199559]
 [ 0.26335492 -0.92555649 -0.24203288 -0.12413481]
 [-0.58125401 -0.02109478 -0.14089226 -0.80115427]
 [-0.56561105 -0.06541577 -0.6338014   0.52354627]]

[20.89551896 11.75513248  4.7013819   1.75816839]

[[ 1.08374515e-01  9.98503796e-02  1.13323362e-01 ... -7.27833114e-02
  -6.58701606e-02 -4.59092965e-02]
 [-4.30198387e-02  5.57547718e-02  2.70926177e-02 ... -2.26960075e-02
  -8.64611208e-02  1.89567788e-03]
 [ 2.59377669e-02  4.83370288e-02 -1.09498919e-02 ... -3.81328738e-02
  -1.98113038e-01 -1.12476331e-01]
 ...
 [ 5.42576376e-02  5.32189412e-03  2.76010922e-02 ...  9.89545817e-01
  -1.40226565e-02 -7.86338250e-04]
 [ 1.60581494e-03  8.56651825e-02  1.78415121e-01 ... -1.24233079e-02
   9.52228601e-01 -2.19591161e-02]
 [ 2.27770498e-03  6.44405862e-03  1.49430370e-01 ... -6.58105858e-04
  -2.32385318e-02  9.77215825e-01]]

U(eigenvector)np.linalg.eigh()的结果svd()相同,但是S(variance/eigenvalue)的值不同。

我想念什么吗? 有人可以解释np.linalg.svd() function中的U,S和V吗?

0 个答案:

没有答案