Regression Invariance Under Feature Transformations
Statistics & ExperimentsModel answerLast updated
Show mathematically how ordinary least squares predictions behave when features are linearly transformed, and contrast with regularized methods.
Consider two regression setups. In the first, you regress response y on features X₁ and X₂. In the second, you apply an invertible linear transformation to create new features Z = XT, where T is a 2×2 invertible matrix. For concreteness, take T = [[1, 1], [-1, 1]], so the transformed features are Z₁ = X₁ - X₂ and Z₂ = X₁ + X₂.
Part (a): Demonstrate that ordinary least squares produces identical predictions regardless of whether you fit on the original features X or the transformed features Z. Derive the relationship between the coefficient vectors in the two parameterizations.
Part (b): Analyze whether this invariance extends to ridge regression (with penalty λ||β||₂²) and lasso regression (with penalty λ||β||₁). State precisely under what conditions each method's predictions remain unchanged when features are transformed. Consider both the given transformation T and the general case.
Part (c): For ridge regression, write out the solution formulas and determine when predictions stay the same across parameterizations. For lasso, construct a specific numerical example demonstrating that predictions can differ between the original and transformed features.
Hints
Hint 1
OLS fits a projection onto the column space of the design matrix. How does an invertible transformation affect this space?
Hint 2
Regularization penalties apply to the coefficient vector. When you substitute the transformed coefficients, what penalty does this induce in the original parameterization?
Hint 3
The ℓ₂ norm is preserved by orthogonal matrices, while the ℓ₁ norm is preserved only by signed permutations. What type of matrix is the given T?
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer
Part (a): OLS Invariance
Geometric Argument
Ordinary least squares finds the orthogonal projection of y onto the column space of the design matrix. When we transform Z = XT with invertible T, the column space remains unchanged: any linear combination of columns in Z can be written as ZTv = X(Tv), which is a linear combination of columns in X. Since T is invertible, this mapping is bijective. Therefore, both models project onto the same subspace, yielding identical fitted values ŷ.
Algebraic Derivation
Assuming X has full column rank, the OLS solutions are:
β_X = (X'X)⁻¹X'y
β_Z = (Z'Z)⁻¹Z'y = (T'X'XT)⁻¹T'X'y
Expanding the second expression:
β_Z = T⁻¹(X'X)⁻¹(T')⁻¹T'X'y = T⁻¹(X'X)⁻¹X'y = T⁻¹β_X
The predictions satisfy:
ŷ_Z = Zβ_Z = XT·T⁻¹β_X = Xβ_X = ŷ_X
For the given T: With T = [[1,1],[-1,1]], we have T⁻¹ = 0.5[[1,-1],[1,1]], giving:
β_Z1 = (β_X1 - β_X2)/2β_Z2 = (β_X1 + β_X2)/2
This correctly recovers the original model: β_Z1(X₁-X₂) + β_Z2(X₁+X₂) = β_X1·X₁ + β_X2·X₂.
Part (b): Regularization and Invariance Conditions
Key Framework
Substituting β = Tβ_Z into the penalized objective:
min_β_Z ||y - XTβ_Z||² + λ·penalty(β_Z)
⟺ min_β ||y - Xβ||² + λ·penalty(T⁻¹β)
Predictions remain invariant for all datasets if and only if penalty(T⁻¹β) = penalty(β) for every β, meaning T⁻¹ must be an isometry of the penalty norm.
Ridge Regression
The ℓ₂ penalty transforms as:
||β_Z||₂² = ||T⁻¹β||₂² = β'(T')⁻¹T⁻¹β = β'(TT')⁻¹β
This equals ||β||₂² if and only if TT' = I, i.e., T is orthogonal.
For the given T: We have TT' = [[2,0],[0,2]] = 2I. So T = √2·Q where Q is a 45° rotation. Ridge regression with penalty parameter λ_Z on features Z is equivalent to ridge with parameter λ_X = λ_Z/2 on features X. If you use the same λ for both, predictions will differ. With the rescaling λ_Z = 2λ_X, predictions match exactly.
Lasso Regression
The isometries of the ℓ₁ norm are only signed permutations (possibly scaled uniformly). A signed permutation reorders coordinates and flips signs: β → Dπ(β) where D is diagonal with ±1 entries and π is a permutation.
For the given T: Since T/√2 is a 45° rotation (not a signed permutation), lasso is not invariant under T for any choice of λ. The rotation mixes coordinates in a way that fundamentally changes which sparse solutions are preferred.
Part (c): Detailed Analysis
Ridge Solution
β_X = (X'X + λI)⁻¹X'y
β_Z = (T'X'XT + λI)⁻¹T'X'y
Rewriting the Z-solution:
β_Z = T⁻¹(X'X + λ(TT')⁻¹)⁻¹X'y
ŷ_Z = X(X'X + λ(TT')⁻¹)⁻¹X'y
Comparing with ŷ_X = X(X'X + λI)⁻¹X'y, predictions are identical for all y exactly when (TT')⁻¹ = I.
Numerical verification: Let n=2, X = I₂, y = (3, 1), λ = 1.
Original features: β_X = (3/2, 1/2), so ŷ = (3/2, 1/2)
Transformed features with λ=1: We have Z = T, Z'Z = 2I, Z'y = (2, 4), giving β_Z = (2,4)/3, and ŷ = (2, 2/3) — different!
Transformed features with λ=2: Now β_Z = (2,4)/4 = (1/2, 1), and ŷ = T(1/2, 1) = (3/2, 1/2) — matches!
Lasso Counterexample
For orthogonal designs X'X = dI, lasso has closed form: β_j = sign(x_j'y)·max(|x_j'y| - λ, 0)/d (soft thresholding).
Using X = I₂, y = (3, 1), λ = 1:
Original model (d=1): β_X = (2, 0) (second feature dropped), giving ŷ = (2, 0)
Transformed model (d=2, Z'y = (2, 4)): β_Z = (0.5, 1.5), giving ŷ = 0.5(1,-1) + 1.5(1,1) = (2, 1)
The predictions differ: (2, 0) versus (2, 1). In the original parameterization, the transformation yields Tβ_Z = (2, 1), which is not sparse. No rescaling of λ can reconcile this — to match ŷ = (2,0) would require β_Z = T⁻¹(2,0) = (1,1), but this is impossible with soft thresholding on Z'y = (2,4).
Summary
- OLS: Predictions always invariant under invertible transforms; coefficients relate as
β_Z = T⁻¹β_X - Ridge: Predictions invariant only when
Tis orthogonal (or with appropriateλrescaling for scaled orthogonalT) - Lasso: Predictions invariant only for signed permutations; rotations fundamentally change the solution
Common Pitfalls:
- Confusing coefficient invariance with prediction invariance (only predictions are preserved in OLS)
- Miscalculating that the given
Tis orthogonal (it's actually√2times a rotation) - Getting the direction wrong:
β_Z = T⁻¹β_X, notTβ_X - Thinking
λrescaling can fix lasso invariance under rotations (it cannot) - Forgetting that in practice, feature standardization is itself a data-dependent transformation that affects regularized methods