7 Singular Value Decomposition
Singular Value Decomposition (SVD) is a powerful mathematical tool in linear algebra used to decompose a matrix into three simpler matrices. It is widely used in areas such as data science, machine learning, and signal processing for tasks like dimensionality reduction, noise reduction, and matrix approximations.
7.1 What is SVD?
Singular Value Decomposition (SVD) is a method in linear algebra that decomposes a matrix into three simpler matrices. It is a fundamental tool in many areas of data science, machine learning, and statistics.
For a given matrix
Where:
is the original matrix. is an orthogonal matrix whose columns are the left singular vectors of . is an diagonal matrix whose diagonal entries are the singular values of . is an orthogonal matrix whose rows are the right singular vectors of .
7.2 SVD in 2D Matrix
Let’s start with the matrix:
7.2.1 Step 1: Compute and
Compute
Transpose
Now compute:
Compute
7.2.2 Step 2: Compute Eigenvalues and Singular Values
Eigenvalues of
Solve
Expanding:
Simplify:
Solve for
Singular Values:
The singular values are the square roots of the eigenvalues:
7.2.3 Step 3: Compute (Right Singular Vectors)
The eigenvectors of
For
Solve:
Simplify:
From this, the eigenvector is:
For
Solve:
Simplify:
From this, the eigenvector is:
Thus:
7.2.4 Step 4: Compute (Left Singular Vectors)
The eigenvectors of
7.2.5 Step 5: Construct
The diagonal matrix
7.2.6 Step 6: Verify
Reconstruct
7.3 SVD for a 3D Matrix
We start with the matrix:
7.3.1 Step 1: Compute and
First, transpose
Now compute:
Compute
7.3.2 Step 2: Compute Eigenvalues and Singular Values
Eigenvalues of
Solve
The eigenvalues are:
The singular values are the square roots of the eigenvalues:
7.3.3 Step 3: Compute (Right Singular Vectors)
The eigenvectors of
7.3.4 Step 4: Compute (Left Singular Vectors)
The eigenvectors of
7.3.5 Step 5: Construct
The diagonal matrix
7.3.6 Step 6: Verify
Reconstruct
7.4 SVD for Movie Recommendation System
We will use the following user-item rating matrix as an example, where the ?
represents the missing ratings:
User/Item | Movie 1 | Movie 2 | Movie 3 | Movie 4 |
---|---|---|---|---|
User 1 | 5 | 3 | ? | 1 |
User 2 | 4 | ? | ? | 1 |
User 3 | 1 | 1 | ? | 5 |
User 4 | 1 | ? | ? | 4 |
User 5 | ? | 1 | 5 | 4 |
We aim to predict the missing ratings using SVD.
7.4.1 Step 1: The User-Item Rating Matrix
We begin with the following user-item matrix
We want to predict the missing ratings, for example, User 1’s rating for Movie 3.
7.4.2 Step 2: Apply SVD
SVD decomposes the matrix
Where:
is the user matrix (an orthogonal matrix of size ), is a diagonal matrix of singular values (of size ), is the transpose of the movie matrix (an orthogonal matrix of size ).
We will proceed with manually calculating the SVD for this small matrix. Normally, you would use a computational tool (e.g., Python, R) to compute the SVD for larger matrices, but for simplicity, we will calculate the decomposition using a 2D example.
Compute
First, we compute
Next, compute
Simplifying the matrix multiplication gives:
Eigenvalue Decomposition of
We solve the eigenvalue equation
Compute
The columns of the matrix
Compute
Similarly, we compute the eigenvectors of
The eigenvectors of
7.4.3 Step 3: Reconstruct the Matrix with , , and
After applying SVD, we can approximate
Where
Using the top 2 singular values (as an approximation), we reconstruct the matrix:
7.4.4 Step 4: Predict Missing Ratings
Now that we have the approximate matrix
7.4.5 Step 5: Recommendation
By filling in the missing ratings, the system can recommend movies to users. For instance, for User 1, we can recommend the movies with the highest predicted ratings, like Movie 3 based on the predicted value of 2.4.
Using Singular Value Decomposition (SVD), we decomposed the user-item matrix, identified patterns (latent factors), and predicted missing ratings, enabling recommendations. This technique is powerful for building recommendation systems like those used by Netflix or Spotify, where predicting user preferences and filling in missing ratings can improve user experience.
7.4.6 Python Code
Click Link here
7.5 Conclusion
SVD is a powerful tool in Data Science, allowing us to uncover the structure of data, reduce dimensions, and improve computational efficiency. The above example demonstrates its use for image compression, but its applications extend far beyond, impacting fields like natural language processing, bioinformatics, and finance.