How to Calculate the SVD from Scratch with Python

Last Updated on October 18, 2019

Matrix decomposition, also known as matrix factorization, involves describing a given matrix using its constituent elements.

Perhaps the most known and widely used matrix decomposition method is the Singular-Value Decomposition, or SVD. All matrices have an SVD, which makes it more stable than other methods, such as the eigendecomposition. As such, it is often used in a wide array of applications including compressing, denoising, and data reduction.

In this tutorial, you will discover the Singular-Value Decomposition method for decomposing a matrix into its constituent elements.

After completing this tutorial, you will know:

  • What Singular-value decomposition is and what is involved.
  • How to calculate an SVD and reconstruct a rectangular and square matrix from SVD elements.
  • How to calculate the pseudoinverse and perform dimensionality reduction using the SVD.

Kick-start your project with my new book Linear Algebra for Machine Learning, including step-by-step tutorials and the Python source code files for all examples.

Let’s get started.

  • Update Mar/2018: Fixed typo in reconstruction. Changed V in code to VT for clarity. Fixed typo in the pseudoinverse equation.
  • Update Apr/2019: Fixed a small typo re array sizes in the explanation of the SVD
    To finish reading, please visit source site