Singular Value Decomposition: SVD
Explore the concept of Singular Value Decomposition SVD, its role in matrix factorization, and how to compute it using Python. Understand orthogonal diagonalization, the significance of singular values and vectors, and the economic SVD approach to handle zeros in the singular values. This lesson helps you grasp the mathematical foundations and practical implementations essential for data science applications.
Definition
The Singular Value Decomposition (SVD) of an matrix, , is the factorization of , multiplied by the product of three matrices:
, where the matrices and are orthogonal and the matrix, , is a
SVD in numpy
We can compute SVD of a matrix, A, using U,S,Vt = numpy.linalg.svd(A), where S is an array containing diagonal entries of and Vt is .
The diag function in the implementation below converts the S array into the generalized diagonal matrix, . We’ve used the D variable to represent in the code.
Singular values and vectors
- The diagonal values of are the singular values of .
- The columns of are the left singular vectors of .
- The rows of are the right singular vectors of .
We assume that the singular values in are in descending order. That’s how
numpy.linalg.svdreturns the values inS. We can arrange the values in any order if we’re provided the corresponding arrangement of the columns of and the rows of .
Economic SVD
When has some zeros in the diagonal, we can drop them. We can also drop the corresponding columns in and the rows in . If is the diagonal matrix with only non-zero singular values, and and are the matrices of the corresponding columns and rows in and , respectively, then
...