ML MATH & LINEAR ALGEBRA · INTERVIEW QUESTION
Explain the relationship between eigendecomposition and diagonalization. Why is it useful?
🔴 advanced · Linear Algebra
Hint: A = PDP⁻¹ where D is diagonal with eigenvalues.
Answer
A square matrix can be diagonalized as:
where contains eigenvectors as columns and is diagonal with eigenvalues.
Why is this useful?
- Matrix powers: — just raise diagonal entries to power
- Matrix exponential: — used in continuous-time models
- PCA: eigendecomposition of covariance matrix gives principal components
- Spectral clustering: eigendecomposition of graph Laplacian
python
import numpy as np
A = np.array([[2, 1], [1, 2]])
eigenvalues, P = np.linalg.eig(A)
D = np.diag(eigenvalues)
# Verify: A = P @ D @ P^{-1}
A_reconstructed = P @ D @ np.linalg.inv(P)
print(np.allclose(A, A_reconstructed)) # True
# Matrix power made easy
A_cubed = P @ np.diag(eigenvalues**3) @ np.linalg.inv(P)Not all matrices are diagonalizable (need linearly independent eigenvectors). Symmetric matrices are always diagonalizable with orthogonal eigenvectors (spectral theorem).
Related questions
- What is the difference between eigenvalues and singular values?
- Explain the role of SVD in PCA. How does truncated SVD relate to dimensionality reduction?
- What is a matrix and why are matrices important in machine learning?
- What is the rank of a matrix? Why does it matter in ML?
- What is a dot product and why does it matter in ML?