Relate coefficients under linear feature transformation
DatabricksData Scientist · Technical ScreenLast updated
This question tests the relationship between regression coefficients when predictors undergo linear transformations, specifically focusing on scaling and centering transformations.
Linear Feature Transformation and Coefficient Invariance
Consider a standard multiple linear regression model:
Y = X * beta + epsilon, where Y is an n x 1 vector of observations, X is an n x p design matrix (including an intercept column), beta is a p x 1 vector of coefficients, and epsilon is an n x 1 vector of i.i.d. Gaussian noise.
Suppose we perform a linear transformation on one of the features. Specifically, let the j-th predictor (where j > 1, i.e., not the intercept) be transformed from x_j to x'_j = a * x_j + b, where a is a non-zero scalar and b is a constant.
Tasks:
- Derive how the coefficient
beta_jfor the transformed featurex'_jrelates to the original coefficientbeta_jin the new modelY = X' * beta' + epsilon. - Explain what happens to the intercept coefficient
beta_0due to this transformation. - If we standardize all features (i.e.,
a = 1/std(x_j)andb = -mean(x_j)/std(x_j)), how do the coefficients of the standardized model relate to the original ones, and why might this be preferred in practice?
Constraints:
- Assume
Xhas full column rank. - Assume OLS estimation is used for both models.
Example:
If Y = 2 + 3 * x1 and we transform x1 to x1' = 2 * x1 + 1:
- The new model becomes
Y = 2 + 3 * ((x1' - 1) / 2) = (2 - 1.5) + 1.5 * x1' = 0.5 + 1.5 * x1'. - Here,
beta_0changes from2to0.5andbeta_1changes from3to1.5.
Hints
Hint 1
Substitute the inverse transformation `x_j = (x'_j - b) / a` directly into the original regression equation.
Hint 2
Group the terms associated with the constant `x'_j` and the constant `1` (the intercept) to identify the new parameters.
Hint 3
Consider how the magnitude of the features affects the optimization surface (e.g., condition number of the matrix X'X) when choosing to standardize variables.
Follow-up questions
- How would these relationships change if we used Ridge regression (L2 regularization) instead of OLS?
- If two features are perfectly linearly dependent after transformation, how does this affect the OLS estimator and the identifiability of the model?
- Why does feature scaling improve the convergence speed of gradient descent even if it doesn't change the theoretical OLS solution?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.