Span, Linear Independence, Basis, Rank & The Four Subspaces
Understand true data dimensionality, why redundant features break regression, and Gilbert Strang's Four Fundamental Subspaces
Rank & Linear Independence explain Multicollinearity, the One-Hot Dummy Variable Trap, and why LoRA fine-tuning works!
Modern AI breakthroughs like LoRA prove that giant weight updates ΔW actually have tiny effective RANK (r = 8 instead of 4096) — slashing GPU VRAM by 98%!
Adding a redundant feature (e.g., Temp_F alongside Temp_C, or keeping all K one-hot columns with an intercept) drops Rank(X) < d and breaks Linear Regression coefficient interpretability!
'What happens to OLS Linear Regression when two features are perfectly collinear, and how does Ridge fix it?' — a guaranteed Data Science interview classic!
Your housing dataset has 5 columns: [SqFt, Bedrooms, Temp_C, Temp_F, Price], where Temp_F = 1.8·Temp_C + 32. What is the maximum possible RANK of the 4 feature columns?
- Visualize the Span of a set of vectors and test whether vectors are Linearly Independent or Dependent (collinear).
- Define a Basis and explain how changing basis (like PCA!) rotates coordinates without losing information.
- Identify all Four Fundamental Subspaces (Column Space, Row Space, Null Space, Left Null Space) and their exact dimensions.
- Apply the Rank–Nullity Theorem to diagnose multicollinearity, dummy-variable traps, and low-rank structure in real ML datasets.
Just because a dataset has 50 columns does not mean it carries 50 independent dimensions of information! Span, Linear Independence, Basis, and Rank give you X-ray vision into the true geometry of your feature matrix and explain why redundant columns create fatal multicollinearity.
1. Span & Linear Independence — How Much Space Can Your Vectors Reach?
Imagine a video-game character with two joystick moves:
- If Move 1 walks East and Move 2 walks North, you can reach ANY spot on the entire 2D map! (Span = whole 2D plane, Rank = 2!)
- Now imagine Move 1 walks 1 step East and Move 2 walks 2 steps East — you are trapped forever on one 1D road! Move 2 was completely redundant (Linearly Dependent, Rank = 1)!
What Is a Span?
The span of vectors is the set of every single vector you can build using linear combinations:
- Span of 1 non-zero vector in : An infinite 1D line passing through the origin.
- Span of 2 non-parallel vectors in : The entire 2D plane !
- Span of 2 parallel (collinear) vectors in : Still trapped on the same 1D line — the second vector added zero new reach!
Linear Independence vs. Dependence
Vectors are linearly independent if no vector is redundant (none can be written as a linear combination of the others). Formally, the only way to combine them to get zero is the trivial all-zeros solution: If you can find any non-zero weights giving (e.g. ), they are linearly dependent!
Worked Example 1 — Testing Linear Independence by Hand
- Are and independent?
- No! Notice , so (non-zero weights!). They are linearly dependent and span only a 1D line.
- Are , , independent?
- No! Look closely: ! So . These 3 vectors only span a 2D plane inside !
Every input feature column either adds NEW information (rank) OR collapses into redundancy (nullspace)!
Number of truly independent signal directions kept by matrix A.
Are the three 2D vectors [1, 0]ᵀ, [0, 1]ᵀ, and [2, 3]ᵀ linearly independent or dependent? Why?
2. Basis & Coordinates — Choosing the Best Axes for Your Data
Here is a wild miracle of Linear Algebra that surprises everyone: for ANY rectangular matrix (even 10,000 rows × 5 columns!), the number of independent rows ALWAYS equals the number of independent columns — so Row Rank = Column Rank = rank(A)!
A basis of a vector space is a set of vectors that is just right:
- They span all of (enough vectors to reach every point), AND
- They are linearly independent (no redundant vectors!).
Every vector has a unique coordinate representation in a given basis!
- The standard basis of is .
- Why ML engineers love changing basis: The standard feature axes (height, weight, waist size) are heavily correlated. PCA simply finds a new orthonormal rotated basis where the first axis captures maximum variance and all axes are uncorrelated!
Worked Example 2 — Expressing a Point in a New Basis
Suppose our basis is and . What are the coordinates of in this new basis? Solve :
- and .
- Adding gives , and . Check: !
Pause & Check: A matrix A has shape (1000, 4) — 1,000 rows and 4 columns. What is the LARGEST possible value of rank(A)?
3. Matrix Rank, The Four Fundamental Subspaces & Rank–Nullity
Every Data Scientist hits the Dummy Variable Trap at least once: you one-hot encode is_Day and is_Night, keep an intercept column of all 1s, and suddenly is_Day + is_Night = 1 creates exact linear dependence! Toggle redundant ML columns below to watch Rank(X) drop and OLS crash live!
For any matrix , its rank is the number of linearly independent columns — which astonishingly ALWAYS equals the number of linearly independent rows (and the number of pivots after Gaussian elimination, and the number of non-zero singular values!).
Every matrix naturally carves input space and output space into 4 Fundamental Subspaces:
- Column Space (dim ): Span of 's columns — all possible model predictions .
- Row Space (dim ): Span of 's rows — the active input directions that preserves.
- Null Space (dim ): All input vectors killed by ().
- Left Null Space (dim ): All vectors orthogonal to every column of () — in Linear Regression, the OLS residual vector lives right here!
The Rank–Nullity Theorem
Toggle redundant columns in a Data Science feature table below and watch Rank(X) vs. number of columns — see why redundant features make (XᵀX)⁻¹ crash in Linear Regression!
A feature matrix X has shape (500, 15) and rank 12. What are the dimensions of (a) Column Space C(X), (b) Null Space N(X), and (c) Left Null Space N(Xᵀ)?
4. Multicollinearity & The Dummy-Variable Trap in Data Science
Now see how Rank & Null Space explain two classic Data Science bugs instantly:
- Duplicate / Derived Columns: If your dataset includes both
price_usdandprice_cents = 100 * price_usd, column 3 is a scalar multiple of column 2. Vector sits in , so for any — infinitely many OLS solutions! - The One-Hot Dummy-Variable Trap: Suppose you one-hot encode
region ∈ {East, West, North}into 3 binary columnsis_east, is_west, is_northAND keep an all-ones intercept column1. Notice: Fix: Drop one reference category (drop_first=True) in unregularized OLS, OR use Ridge/L2 regularization!
The exact honest questions almost every beginner wonders — answered in plain English without hiding behind jargon.
Technically yes (rank = full), BUT your matrix becomes ill-conditioned (almost singular!), causing OLS regression weights to explode into absurd opposites like +50,000 and −50,000! That's why Data Scientists check VIF (Variance Inflation Factor) and use Ridge Regression (L2) to stabilize near-collinear features!
v₁ and v₂ are linearly independent — they form a valid basis reaching every single point in ℝ²!
Diagnosing Multicollinearity (VIF & matrix_rank)
Checking np.linalg.matrix_rank(X) < X.shape[1] immediately catches exact feature redundancies before fitting OLS or logistic regression.
Low-Rank Structure in Recommender Systems & LoRA
A rank-r matrix has only r independent basis patterns — allowing a 4096×4096 LLM weight update to be represented cleanly as a rank-16 product BA.
PCA as Optimal Orthonormal Change of Basis
PCA replaces correlated feature columns with an orthogonal basis ordered by variance so dropping low-variance basis vectors compresses data with minimal loss.
Rank Collapse in Deep Attention Networks
Without skip connections and LayerNorm, stacking pure self-attention layers pushes token representations toward rank-1 (all tokens identical) — skip connections preserve full rank!
import numpy as np
# Matrix with a collinear 3rd column (col3 = 100 * col2)
X = np.array([[1000.0, 10.0, 1000.0],
[1500.0, 25.0, 2500.0],
[1200.0, 15.0, 1500.0],
[1800.0, 30.0, 3000.0]])
rank = np.linalg.matrix_rank(X) # 2 (strictly less than 3 columns!)
nullity = X.shape[1] - rank # 1 (1D null space!)
# Extract an orthonormal basis for the Null Space via SVD:
_, S, Vt = np.linalg.svd(X, full_matrices=True)
null_basis = Vt[rank:].T # shape: (3, 1) -> satisfies X @ null_basis ≈ 0!
assert np.allclose(X @ null_basis, 0.0, atol=1e-10)