MLCrack

    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:

    1. Multicollinearity: if rank<p\text{rank} < p (features), features are linearly dependent โ†’ unstable regression
    2. PCA: data's intrinsic dimensionality = effective rank
    3. Matrix factorization: recommender systems use low-rank approximation Rโ‰ˆUVโŠคR \approx UV^\top assuming few latent factors
    4. LoRA: weight matrices with low effective rank motivate low-rank adaptation
    5. SVD: singular values reveal rank; truncated SVD gives best rank-kk 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, ~0

    Numerical rank considers singular values above a threshold (exact rank is fragile with noise).