ML MATH & LINEAR ALGEBRA ยท INTERVIEW QUESTION
What is the rank of a matrix? Why does it matter in ML?
๐ก intermediate ยท Linear Algebra
Hint: Think about linear independence and dimensionality.
Answer
Matrix rank = number of linearly independent rows (or columns). It represents the 'true' dimensionality of the data.
Rank matters in ML:
- Multicollinearity: if (features), features are linearly dependent โ unstable regression
- PCA: data's intrinsic dimensionality = effective rank
- Matrix factorization: recommender systems use low-rank approximation assuming few latent factors
- LoRA: weight matrices with low effective rank motivate low-rank adaptation
- SVD: singular values reveal rank; truncated SVD gives best rank- approximation
python
import numpy as np
A = np.array([[1, 2, 3], [2, 4, 6], [1, 0, 1]])
print(f'Rank: {np.linalg.matrix_rank(A)}') # 2 (row 2 = 2 ร row 1)
# SVD reveals effective rank
U, S, Vt = np.linalg.svd(A)
print(f'Singular values: {S}') # large, large, ~0Numerical rank considers singular values above a threshold (exact rank is fragile with noise).
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?
- Explain the relationship between eigendecomposition and diagonalization. Why is it useful?
- What is a dot product and why does it matter in ML?