Mastering Matrix Decompositions and SVD: Concepts, Patterns, and Pitfalls
When developers interact with matrices—usually via NumPy, PyTorch, or TensorFlow—the mental model is almost entirely wrong. The pervasive misconception is treating a matrix purely as a static grid of numbers, a mere data table resembling an Excel spreadsheet. We load user ratings into a matrix, or image pixels into a tensor, and run black-box API calls like np.linalg.svd. But when algorithms fail to converge or gradients vanish, this superficial understanding collapses.
The truth is that a matrix is not a spreadsheet; it is an active, geometric transformation. A matrix stretches, rotates, and shears space. Matrix Decompositions (LU, QR, Eigendecomposition, and SVD) are algorithms designed to take a complex, messy transformation and break it apart into a sequence of extremely simple, fundamental geometric moves. In this deep dive, we will dismantle the "spreadsheet" misconception, build an intuitive geometric framework, trace how the algorithms actually work under the hood, and conquer the Singular Value Decomposition (SVD)—the most powerful tool in modern machine learning.
1. The Grand Misconception: Matrices as Transformations
Before we can decompose a matrix, we must understand what it is. Consider a 2x2 matrix $A$. When you multiply a vector $x$ by $A$, the vector $x$ is moved to a new location in space. The columns of matrix $A$ literally tell you where the original basis vectors (the X and Y axes) land after the transformation.
If a matrix $A$ applies a chaotic combination of rotation, stretching, and shearing, it is computationally difficult to analyze its properties. Matrix decomposition is the mathematical equivalent of reverse-engineering a complex machine. We want to factorize the chaotic matrix $A$ into a product of simpler matrices (e.g., $A = B \times C \times D$), where each simpler matrix performs only one isolated, elementary geometric action: only a rotation, or only a stretch.
Remember that matrix multiplication is applied right-to-left. If we decompose a matrix into $A = U \Sigma V^T$, and apply it to a vector $x$, the operation is $A x = U (\Sigma (V^T x))$. The transformation $V^T$ acts first, followed by $\Sigma$, and finally $U$. Developers porting mathematical formulas to code often reverse this sequence, resulting in fundamentally broken geometry.
2. LU Decomposition: Automated Gaussian Elimination
2.1 The Concept
If you have ever solved a system of linear equations in high school by adding and subtracting rows until you isolate the variables, you have performed Gaussian elimination. LU Decomposition is simply the algorithmic formalization of Gaussian elimination. It factors a square matrix $A$ into two triangular matrices: $A = LU$.
- L (Lower Triangular): Contains 1s on the diagonal and non-zero values below it. It records the exact steps (row operations) taken during the elimination.
- U (Upper Triangular): Contains non-zero values on and above the diagonal. This is the "row echelon form" resulting from the elimination.
2.2 Why do we care?
Why decompose $A$ into $L$ and $U$ instead of just calculating the inverse $A^{-1}$? Because calculating the inverse of a massive matrix is computationally expensive and numerically unstable. If you want to solve $Ax = b$ for many different $b$ vectors (e.g., varying loads in structural engineering simulations), calculating $A^{-1}$ takes $O(N^3)$ operations. But if you decompose $A$ into $LU$ once, you can solve $LUx = b$ by solving two triangular systems via simple forward and backward substitution. Each substitution takes only $O(N^2)$ time.
3. Eigendecomposition: The Axes of Action
3.1 Eigenvectors and Eigenvalues
Most vectors get knocked off their original span (their line of direction) when passed through a matrix transformation. However, for a given matrix $A$, there are a few special vectors that remain perfectly on their original line. They might get stretched or squished, or flipped backwards, but their direction never changes. These special vectors are the Eigenvectors, and the factor by which they are stretched is the Eigenvalue.
Mathematically: $A v = \lambda v$. The matrix $A$ acting on vector $v$ has the exact same effect as simply scaling $v$ by a scalar number $\lambda$.
3.2 The Diagonalization Theorem
If a square matrix $A$ has linearly independent eigenvectors, we can decompose it into: $A = Q \Lambda Q^{-1}$.
- $Q$: A matrix whose columns are the eigenvectors of $A$. This is a change-of-basis matrix. It rotates space so the eigenvectors become the new coordinate axes.
- $\Lambda$: A diagonal matrix containing the eigenvalues. Because it's diagonal, it only stretches space along the coordinate axes.
- $Q^{-1}$: Reverts the space back to the original orientation.
This is beautiful. A complex transformation is reduced to: rotate space ($Q^{-1}$), stretch axes independently ($\Lambda$), and rotate back ($Q$).
Eigendecomposition has a fatal flaw: it only works on square matrices ($N \times N$). Furthermore, even some square matrices (called defective matrices, like shear transformations) do not have enough linearly independent eigenvectors to form the matrix $Q$. If you attempt to call `np.linalg.eig` on a non-square dataset (like users vs movies), the code will instantly crash.
4. Singular Value Decomposition (SVD): The Universal Tool
Because Eigendecomposition is brittle (failing on non-square or defective matrices), mathematicians developed the ultimate, bulletproof decomposition: the SVD. Every single matrix, regardless of whether it is rectangular ($M \times N$), tall, wide, singular, or defective, is guaranteed to have a Singular Value Decomposition.
SVD factors any matrix $A$ into three distinct components: $A = U \Sigma V^T$.
- $V^T$ (Right Singular Vectors): An orthogonal matrix. Geometrically, it performs a pure rotation in the input space.
- $\Sigma$ (Singular Values): A diagonal matrix. It stretches or shrinks the space along the new orthogonal axes. Unlike eigenvalues, singular values are always real and non-negative.
- $U$ (Left Singular Vectors): An orthogonal matrix. It performs a final rotation to align the output space.
If you have a 1,000,000 x 5,000 matrix of user-movie ratings, SVD finds the orthogonal "concept axes" (e.g., Action vs Romance) that best describe the variance in the data. The largest singular values correspond to the most dominant concepts in the dataset.
import numpy as np
# A user-movie rating matrix (Users x Movies)
A = np.array([
[5, 5, 0, 0],
[5, 5, 0, 0],
[0, 0, 4, 4],
[0, 0, 5, 5]
])
# Perform full SVD
U, Sigma, Vt = np.linalg.svd(A)
# Notice Sigma has two large values (~7.07, ~6.40) and two zeros.
# This proves the rank of the matrix is 2 (there are only 2 true concepts/genres).
print("Singular Values:", np.round(Sigma, 2))
# Output: [7.07 6.4 0. 0. ]5. Worked Trace: The Power Iteration Algorithm
How does software actually compute the dominant eigenvector (and by extension, the leading singular vector) without solving complex polynomial roots? The simplest, most intuitive method is Power Iteration.
The logic is brilliant: Take a random vector. Multiply it by the matrix $A$. The matrix pulls the vector slightly towards its dominant eigenvector. Normalize the vector. Repeat. With every iteration, the vector aligns closer and closer to the dominant axis of the matrix.
def power_iteration(A, num_simulations=10):
# Step 1: Random initial vector
b_k = np.random.rand(A.shape[1])
for _ in range(num_simulations):
# Step 2: Multiply
b_k1 = np.dot(A, b_k)
# Step 3: Normalize
b_k1_norm = np.linalg.norm(b_k1)
b_k = b_k1 / b_k1_norm
return b_k
dominant_vector = power_iteration(A)
# The Rayleigh quotient estimates the eigenvalue
dominant_value = np.dot(dominant_vector.T, np.dot(A, dominant_vector))
This exact iterative principle is the foundation for Google's original PageRank algorithm, finding the dominant eigenvector of the massive internet transition matrix!
6. Frequently Asked Questions
Q1: What is Truncated SVD and why is it used?
In practice, computing the full SVD of a 1-million by 1-million matrix takes days. However, because the $\Sigma$ matrix sorts the singular values from largest to smallest, the vast majority of the data's "information" is captured by the first few singular values. Truncated SVD computes only the top $k$ singular values (using algorithms like Randomized SVD or Lanczos iteration), yielding an incredibly fast and accurate lower-rank approximation of the original matrix. This is the core of Latent Semantic Analysis (LSA) and PCA dimensionality reduction.
Q2: What is the relationship between SVD and PCA?
Principal Component Analysis (PCA) is an algorithm, and SVD is the mathematical engine usually used to execute it. If you mean-center your data matrix $X$, the principal components of PCA are exactly the right singular vectors ($V^T$) obtained from the SVD of $X$. You can also compute PCA via Eigendecomposition of the covariance matrix ($X^T X$), but applying SVD directly to $X$ is vastly more numerically stable and prevents floating-point precision loss.
Q3: Why do we use QR decomposition instead of LU for some tasks?
LU decomposition is fast but highly unstable for certain matrices (especially those requiring pivoting). QR decomposition factors a matrix into an orthogonal matrix $Q$ and an upper triangular matrix $R$. Because orthogonal matrices only rotate space (preserving lengths and angles), QR decomposition is exceptionally numerically stable. It is the backbone of calculating least-squares regression lines and the foundational step in the famous QR Algorithm for finding all eigenvalues of a matrix.
Q4: How does a Recommendation System use SVD?
In Collaborative Filtering, the sparse user-item matrix $R$ is factored into user latent factors and item latent factors. While true SVD cannot handle missing values (it treats blanks as zeros, wildly skewing the geometry), systems use Matrix Factorization (via Gradient Descent or Alternating Least Squares) to approximate the SVD factors only on the known ratings. The dot product of the resulting User row vector and Item column vector accurately predicts the missing rating.
Written by Professor Pixel · CodingPancake · Algorithms & Mathematics Series
1. The Grand Misconception: Matrices as Transformations
Before we can decompose a matrix, we must understand what it is. Consider a 2x2 matrix $A$. When you multiply a vector $x$ by $A$, the vector $x$ is moved to a new location in space. The columns of matrix $A$ literally tell you where the original basis vectors (the X and Y axes) land after the transformation.
If a matrix $A$ applies a chaotic combination of rotation, stretching, and shearing, it is computationally difficult to analyze its properties. Matrix decomposition is the mathematical equivalent of reverse-engineering a complex machine. We want to factorize the chaotic matrix $A$ into a product of simpler matrices (e.g., $A = B \times C \times D$), where each simpler matrix performs only one isolated, elementary geometric action: only a rotation, or only a stretch.
Remember that matrix multiplication is applied right-to-left. If we decompose a matrix into $A = U \Sigma V^T$, and apply it to a vector $x$, the operation is $A x = U (\Sigma (V^T x))$. The transformation $V^T$ acts first, followed by $\Sigma$, and finally $U$. Developers porting mathematical formulas to code often reverse this sequence, resulting in fundamentally broken geometry.
2. LU Decomposition: Automated Gaussian Elimination
2.1 The Concept
If you have ever solved a system of linear equations in high school by adding and subtracting rows until you isolate the variables, you have performed Gaussian elimination. LU Decomposition is simply the algorithmic formalization of Gaussian elimination. It factors a square matrix $A$ into two triangular matrices: $A = LU$.
- L (Lower Triangular): Contains 1s on the diagonal and non-zero values below it. It records the exact steps (row operations) taken during the elimination.
- U (Upper Triangular): Contains non-zero values on and above the diagonal. This is the "row echelon form" resulting from the elimination.
2.2 Why do we care?
Why decompose $A$ into $L$ and $U$ instead of just calculating the inverse $A^{-1}$? Because calculating the inverse of a massive matrix is computationally expensive and numerically unstable. If you want to solve $Ax = b$ for many different $b$ vectors (e.g., varying loads in structural engineering simulations), calculating $A^{-1}$ takes $O(N^3)$ operations. But if you decompose $A$ into $LU$ once, you can solve $LUx = b$ by solving two triangular systems via simple forward and backward substitution. Each substitution takes only $O(N^2)$ time.
3. Eigendecomposition: The Axes of Action
3.1 Eigenvectors and Eigenvalues
Most vectors get knocked off their original span (their line of direction) when passed through a matrix transformation. However, for a given matrix $A$, there are a few special vectors that remain perfectly on their original line. They might get stretched or squished, or flipped backwards, but their direction never changes. These special vectors are the Eigenvectors, and the factor by which they are stretched is the Eigenvalue.
Mathematically: $A v = \lambda v$. The matrix $A$ acting on vector $v$ has the exact same effect as simply scaling $v$ by a scalar number $\lambda$.
3.2 The Diagonalization Theorem
If a square matrix $A$ has linearly independent eigenvectors, we can decompose it into: $A = Q \Lambda Q^{-1}$.
- $Q$: A matrix whose columns are the eigenvectors of $A$. This is a change-of-basis matrix. It rotates space so the eigenvectors become the new coordinate axes.
- $\Lambda$: A diagonal matrix containing the eigenvalues. Because it's diagonal, it only stretches space along the coordinate axes.
- $Q^{-1}$: Reverts the space back to the original orientation.
This is beautiful. A complex transformation is reduced to: rotate space ($Q^{-1}$), stretch axes independently ($\Lambda$), and rotate back ($Q$).
Eigendecomposition has a fatal flaw: it only works on square matrices ($N \times N$). Furthermore, even some square matrices (called defective matrices, like shear transformations) do not have enough linearly independent eigenvectors to form the matrix $Q$. If you attempt to call `np.linalg.eig` on a non-square dataset (like users vs movies), the code will instantly crash.
4. Singular Value Decomposition (SVD): The Universal Tool
Because Eigendecomposition is brittle (failing on non-square or defective matrices), mathematicians developed the ultimate, bulletproof decomposition: the SVD. Every single matrix, regardless of whether it is rectangular ($M \times N$), tall, wide, singular, or defective, is guaranteed to have a Singular Value Decomposition.
SVD factors any matrix $A$ into three distinct components: $A = U \Sigma V^T$.
- $V^T$ (Right Singular Vectors): An orthogonal matrix. Geometrically, it performs a pure rotation in the input space.
- $\Sigma$ (Singular Values): A diagonal matrix. It stretches or shrinks the space along the new orthogonal axes. Unlike eigenvalues, singular values are always real and non-negative.
- $U$ (Left Singular Vectors): An orthogonal matrix. It performs a final rotation to align the output space.
If you have a 1,000,000 x 5,000 matrix of user-movie ratings, SVD finds the orthogonal "concept axes" (e.g., Action vs Romance) that best describe the variance in the data. The largest singular values correspond to the most dominant concepts in the dataset.
import numpy as np
# A user-movie rating matrix (Users x Movies)
A = np.array([
[5, 5, 0, 0],
[5, 5, 0, 0],
[0, 0, 4, 4],
[0, 0, 5, 5]
])
# Perform full SVD
U, Sigma, Vt = np.linalg.svd(A)
# Notice Sigma has two large values (~7.07, ~6.40) and two zeros.
# This proves the rank of the matrix is 2 (there are only 2 true concepts/genres).
print("Singular Values:", np.round(Sigma, 2))
# Output: [7.07 6.4 0. 0. ]5. Worked Trace: The Power Iteration Algorithm
How does software actually compute the dominant eigenvector (and by extension, the leading singular vector) without solving complex polynomial roots? The simplest, most intuitive method is Power Iteration.
The logic is brilliant: Take a random vector. Multiply it by the matrix $A$. The matrix pulls the vector slightly towards its dominant eigenvector. Normalize the vector. Repeat. With every iteration, the vector aligns closer and closer to the dominant axis of the matrix.
def power_iteration(A, num_simulations=10):
# Step 1: Random initial vector
b_k = np.random.rand(A.shape[1])
for _ in range(num_simulations):
# Step 2: Multiply
b_k1 = np.dot(A, b_k)
# Step 3: Normalize
b_k1_norm = np.linalg.norm(b_k1)
b_k = b_k1 / b_k1_norm
return b_k
dominant_vector = power_iteration(A)
# The Rayleigh quotient estimates the eigenvalue
dominant_value = np.dot(dominant_vector.T, np.dot(A, dominant_vector))
This exact iterative principle is the foundation for Google's original PageRank algorithm, finding the dominant eigenvector of the massive internet transition matrix!
6. Frequently Asked Questions
Q1: What is Truncated SVD and why is it used?
In practice, computing the full SVD of a 1-million by 1-million matrix takes days. However, because the $\Sigma$ matrix sorts the singular values from largest to smallest, the vast majority of the data's "information" is captured by the first few singular values. Truncated SVD computes only the top $k$ singular values (using algorithms like Randomized SVD or Lanczos iteration), yielding an incredibly fast and accurate lower-rank approximation of the original matrix. This is the core of Latent Semantic Analysis (LSA) and PCA dimensionality reduction.
Q2: What is the relationship between SVD and PCA?
Principal Component Analysis (PCA) is an algorithm, and SVD is the mathematical engine usually used to execute it. If you mean-center your data matrix $X$, the principal components of PCA are exactly the right singular vectors ($V^T$) obtained from the SVD of $X$. You can also compute PCA via Eigendecomposition of the covariance matrix ($X^T X$), but applying SVD directly to $X$ is vastly more numerically stable and prevents floating-point precision loss.
Q3: Why do we use QR decomposition instead of LU for some tasks?
LU decomposition is fast but highly unstable for certain matrices (especially those requiring pivoting). QR decomposition factors a matrix into an orthogonal matrix $Q$ and an upper triangular matrix $R$. Because orthogonal matrices only rotate space (preserving lengths and angles), QR decomposition is exceptionally numerically stable. It is the backbone of calculating least-squares regression lines and the foundational step in the famous QR Algorithm for finding all eigenvalues of a matrix.
Q4: How does a Recommendation System use SVD?
In Collaborative Filtering, the sparse user-item matrix $R$ is factored into user latent factors and item latent factors. While true SVD cannot handle missing values (it treats blanks as zeros, wildly skewing the geometry), systems use Matrix Factorization (via Gradient Descent or Alternating Least Squares) to approximate the SVD factors only on the known ratings. The dot product of the resulting User row vector and Item column vector accurately predicts the missing rating.
Written by Professor Pixel · CodingPancake · Algorithms & Mathematics Series
1. The Grand Misconception: Matrices as Transformations
Before we can decompose a matrix, we must understand what it is. Consider a 2x2 matrix $A$. When you multiply a vector $x$ by $A$, the vector $x$ is moved to a new location in space. The columns of matrix $A$ literally tell you where the original basis vectors (the X and Y axes) land after the transformation.
If a matrix $A$ applies a chaotic combination of rotation, stretching, and shearing, it is computationally difficult to analyze its properties. Matrix decomposition is the mathematical equivalent of reverse-engineering a complex machine. We want to factorize the chaotic matrix $A$ into a product of simpler matrices (e.g., $A = B \times C \times D$), where each simpler matrix performs only one isolated, elementary geometric action: only a rotation, or only a stretch.
Remember that matrix multiplication is applied right-to-left. If we decompose a matrix into $A = U \Sigma V^T$, and apply it to a vector $x$, the operation is $A x = U (\Sigma (V^T x))$. The transformation $V^T$ acts first, followed by $\Sigma$, and finally $U$. Developers porting mathematical formulas to code often reverse this sequence, resulting in fundamentally broken geometry.
2. LU Decomposition: Automated Gaussian Elimination
2.1 The Concept
If you have ever solved a system of linear equations in high school by adding and subtracting rows until you isolate the variables, you have performed Gaussian elimination. LU Decomposition is simply the algorithmic formalization of Gaussian elimination. It factors a square matrix $A$ into two triangular matrices: $A = LU$.
- L (Lower Triangular): Contains 1s on the diagonal and non-zero values below it. It records the exact steps (row operations) taken during the elimination.
- U (Upper Triangular): Contains non-zero values on and above the diagonal. This is the "row echelon form" resulting from the elimination.
2.2 Why do we care?
Why decompose $A$ into $L$ and $U$ instead of just calculating the inverse $A^{-1}$? Because calculating the inverse of a massive matrix is computationally expensive and numerically unstable. If you want to solve $Ax = b$ for many different $b$ vectors (e.g., varying loads in structural engineering simulations), calculating $A^{-1}$ takes $O(N^3)$ operations. But if you decompose $A$ into $LU$ once, you can solve $LUx = b$ by solving two triangular systems via simple forward and backward substitution. Each substitution takes only $O(N^2)$ time.
3. Eigendecomposition: The Axes of Action
3.1 Eigenvectors and Eigenvalues
Most vectors get knocked off their original span (their line of direction) when passed through a matrix transformation. However, for a given matrix $A$, there are a few special vectors that remain perfectly on their original line. They might get stretched or squished, or flipped backwards, but their direction never changes. These special vectors are the Eigenvectors, and the factor by which they are stretched is the Eigenvalue.
Mathematically: $A v = \lambda v$. The matrix $A$ acting on vector $v$ has the exact same effect as simply scaling $v$ by a scalar number $\lambda$.
3.2 The Diagonalization Theorem
If a square matrix $A$ has linearly independent eigenvectors, we can decompose it into: $A = Q \Lambda Q^{-1}$.
- $Q$: A matrix whose columns are the eigenvectors of $A$. This is a change-of-basis matrix. It rotates space so the eigenvectors become the new coordinate axes.
- $\Lambda$: A diagonal matrix containing the eigenvalues. Because it's diagonal, it only stretches space along the coordinate axes.
- $Q^{-1}$: Reverts the space back to the original orientation.
This is beautiful. A complex transformation is reduced to: rotate space ($Q^{-1}$), stretch axes independently ($\Lambda$), and rotate back ($Q$).
Eigendecomposition has a fatal flaw: it only works on square matrices ($N \times N$). Furthermore, even some square matrices (called defective matrices, like shear transformations) do not have enough linearly independent eigenvectors to form the matrix $Q$. If you attempt to call `np.linalg.eig` on a non-square dataset (like users vs movies), the code will instantly crash.
4. Singular Value Decomposition (SVD): The Universal Tool
Because Eigendecomposition is brittle (failing on non-square or defective matrices), mathematicians developed the ultimate, bulletproof decomposition: the SVD. Every single matrix, regardless of whether it is rectangular ($M \times N$), tall, wide, singular, or defective, is guaranteed to have a Singular Value Decomposition.
SVD factors any matrix $A$ into three distinct components: $A = U \Sigma V^T$.
- $V^T$ (Right Singular Vectors): An orthogonal matrix. Geometrically, it performs a pure rotation in the input space.
- $\Sigma$ (Singular Values): A diagonal matrix. It stretches or shrinks the space along the new orthogonal axes. Unlike eigenvalues, singular values are always real and non-negative.
- $U$ (Left Singular Vectors): An orthogonal matrix. It performs a final rotation to align the output space.
If you have a 1,000,000 x 5,000 matrix of user-movie ratings, SVD finds the orthogonal "concept axes" (e.g., Action vs Romance) that best describe the variance in the data. The largest singular values correspond to the most dominant concepts in the dataset.
import numpy as np
# A user-movie rating matrix (Users x Movies)
A = np.array([
[5, 5, 0, 0],
[5, 5, 0, 0],
[0, 0, 4, 4],
[0, 0, 5, 5]
])
# Perform full SVD
U, Sigma, Vt = np.linalg.svd(A)
# Notice Sigma has two large values (~7.07, ~6.40) and two zeros.
# This proves the rank of the matrix is 2 (there are only 2 true concepts/genres).
print("Singular Values:", np.round(Sigma, 2))
# Output: [7.07 6.4 0. 0. ]5. Worked Trace: The Power Iteration Algorithm
How does software actually compute the dominant eigenvector (and by extension, the leading singular vector) without solving complex polynomial roots? The simplest, most intuitive method is Power Iteration.
The logic is brilliant: Take a random vector. Multiply it by the matrix $A$. The matrix pulls the vector slightly towards its dominant eigenvector. Normalize the vector. Repeat. With every iteration, the vector aligns closer and closer to the dominant axis of the matrix.
def power_iteration(A, num_simulations=10):
# Step 1: Random initial vector
b_k = np.random.rand(A.shape[1])
for _ in range(num_simulations):
# Step 2: Multiply
b_k1 = np.dot(A, b_k)
# Step 3: Normalize
b_k1_norm = np.linalg.norm(b_k1)
b_k = b_k1 / b_k1_norm
return b_k
dominant_vector = power_iteration(A)
# The Rayleigh quotient estimates the eigenvalue
dominant_value = np.dot(dominant_vector.T, np.dot(A, dominant_vector))
This exact iterative principle is the foundation for Google's original PageRank algorithm, finding the dominant eigenvector of the massive internet transition matrix!
6. Frequently Asked Questions
Q1: What is Truncated SVD and why is it used?
In practice, computing the full SVD of a 1-million by 1-million matrix takes days. However, because the $\Sigma$ matrix sorts the singular values from largest to smallest, the vast majority of the data's "information" is captured by the first few singular values. Truncated SVD computes only the top $k$ singular values (using algorithms like Randomized SVD or Lanczos iteration), yielding an incredibly fast and accurate lower-rank approximation of the original matrix. This is the core of Latent Semantic Analysis (LSA) and PCA dimensionality reduction.
Q2: What is the relationship between SVD and PCA?
Principal Component Analysis (PCA) is an algorithm, and SVD is the mathematical engine usually used to execute it. If you mean-center your data matrix $X$, the principal components of PCA are exactly the right singular vectors ($V^T$) obtained from the SVD of $X$. You can also compute PCA via Eigendecomposition of the covariance matrix ($X^T X$), but applying SVD directly to $X$ is vastly more numerically stable and prevents floating-point precision loss.
Q3: Why do we use QR decomposition instead of LU for some tasks?
LU decomposition is fast but highly unstable for certain matrices (especially those requiring pivoting). QR decomposition factors a matrix into an orthogonal matrix $Q$ and an upper triangular matrix $R$. Because orthogonal matrices only rotate space (preserving lengths and angles), QR decomposition is exceptionally numerically stable. It is the backbone of calculating least-squares regression lines and the foundational step in the famous QR Algorithm for finding all eigenvalues of a matrix.
Q4: How does a Recommendation System use SVD?
In Collaborative Filtering, the sparse user-item matrix $R$ is factored into user latent factors and item latent factors. While true SVD cannot handle missing values (it treats blanks as zeros, wildly skewing the geometry), systems use Matrix Factorization (via Gradient Descent or Alternating Least Squares) to approximate the SVD factors only on the known ratings. The dot product of the resulting User row vector and Item column vector accurately predicts the missing rating.
Written by Professor Pixel · CodingPancake · Algorithms & Mathematics Series