0
$\begingroup$

My understanding is that a SVD done on a raw data matrix M and a PCA done on its covariance matrix C should return the same eigen/singular values.

I have a 2736 x 356 data matrix and am using the numpy.linalg package to run both the SVD and PCA and construct the covariance matrix.

When I run:

u, s, v = np.linalg.svd(final_matrix, full_matrices=False)
print(np.shape(final_matrix))
print(np.shape(u))
print(np.shape(s))
print(np.shape(v))

I get:

(2736, 356)
(2736, 356)
(356,)
(356, 356)

and when I run:

cov_matrix = np.cov(final_matrix)
vals, vecs = np.linalg.eig(cov_matrix)
print(np.shape(cov_matrix))
print(np.shape(vals))
print(np.shape(vecs))

I get:

(2736, 2736)
(2736,)
(2736, 2736)

So in the first case, I get a # of singular values equal to the # of columns in the data matrix and in the second, I get a # of eigenvalues equal to the # of rows.

I tried running the PCA using the covariance matrix of the transposed data matrix, which returned np.shape(vals) = (356,), same as the SVD. But I don't know if that's the correct solution and additionally, the eigen/singular values themselves are different between the PCA and SVD.

Is my inital assumption correct? If so, what do I need to do in order for the methods to return the correct results?

$\endgroup$
  • 4
    $\begingroup$ You had better check to see how many of those extra eigenvalues are nonzero :-) It will help to work with a smaller problem: perhaps two rows and one column? $\endgroup$ – whuber Jul 2 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.