This exercise is a continuation of exercise 2 from homework 1. We will use the same function to generate our data set, still staying with a simple function \( y(x) \) which we want to fit using linear regression, but now extending the analysis to include the Ridge and the Lasso regression methods. You can use the code under the Regression as an example on how to use the Ridge and the Lasso methods, see the regression slides).
We will thus again generate our own dataset for a function \( y(x) \) where \( x \in [0,1] \) and defined by random numbers computed with the uniform distribution. The function \( y \) is a quadratic polynomial in \( x \) with added stochastic noise according to the normal distribution \( \cal{N}(0,1) \).
The following simple Python instructions define our \( x \) and \( y \) values (with 100 data points).
x = np.random.rand(100,1)
y = 5*x*x+0.1*np.random.randn(100,1)
The theory behind this exercise will be covered during the lectures of week 36. It requires reading chapter three of Hastie et al, in particular the derivations preceeding equation (3.49) as the well as the material in the Regression slides that deal with the singular value decomposition.
Using the singular value decomposition, show that the variance of the direction vector \( \hat{z}_i=\hat{X}\hat{v}_i=\hat{u}_1d_1 \) is equal to (equation (3.49) of Hastie et al.) $$ \mathrm{Var}(\hat{z}_i)=\frac{d_i^2}{N}, $$ where \( d_i \) are the singular values of the matrix \( \hat{X} \). In Hastie et al, the matrix elements of \( X \) are centered. The consequence is that the mean values of for example \( \hat{u}_i \) are zero.
Give an interpretation of these results, in particular in connection with the variance of the coefficients you obtained in the previous exercise.
A possible way to show why \( \left \langle \hat u_i \right \rangle = 0 \) given that the columns of \( \hat X \) is centered is by considering \( \left \langle \hat X \hat v_i \right \rangle \): $$ \begin{align*} \left \langle \hat X \hat v_i \right \rangle &= \frac{1}{N}\sum_j ( \hat X \hat v_i )_j \\ &= \frac{1}{N}\sum_j \sum_k x_{jk}\hat v_i(k)\\ &= \frac{1}{N}\sum_k \hat v_i(k) \sum_j x_{jk} \\ &= \sum_k \hat v_i(k)\left( \frac{1}{N}\sum_j x_{jk} \right) \\ &= \sum_k \hat v_i(k) \left \langle \hat x_k \right \rangle \end{align*} $$
where \( x_{jk} \) being the element of \( \hat X \) at row \( j \) and column \( k \), \( ( \hat X \hat v_i )_j \) the \( j \)-th element of the vector \( \hat X \hat v_i \), \( \hat x_k \) being the \( k \)-th column vector of \( \hat X \), and \( \hat v_i(k) \) the \( k \)-th element of the vector \( \hat v_i \).
Since the columns of \( \hat X \) are assumed to be centered, \( \left \langle \hat x_k \right \rangle = 0 \) for all \( k \). This gives that \( \left \langle \hat X \hat v_i \right \rangle = 0 \).
But \( \left \langle \hat X \hat v_i \right \rangle = \left \langle \hat u_i d_i \right \rangle = d_i \left \langle \hat u_i \right \rangle \).
Since $ \left \langle \hat X \hat v_i \right \rangle = 0$, then \( d_i \left \langle \hat u_i \right \rangle = 0 \) also. Assuming that \( d_i \neq 0 \) (otherwise the variance in the exercise would just be zero), gives that \( \left \langle \hat u_i \right \rangle = 0 \).
Regarding \( \hat V \) and using the similar approach as above by computing \( \left \langle \hat X^T \hat u_i \right \rangle = d_i \left \langle \hat v_i \right \rangle \), we have $$ \begin{align*} \left \langle \hat X^T \hat u_i \right \rangle &= \frac{1}{N}\sum_j ( \hat X^T \hat u_i )_j \\ &= \frac{1}{N}\sum_j \sum_k x_{kj} \hat u_i(k)\\ &= \frac{1}{N}\sum_k \hat u_i(k) \sum_j x_{kj} \\ &= \frac{1}{N}\sum_k \hat u_i(k) \sum_j x_{kj} \\ &= \sum_k \hat u_i(k) \left( \frac{1}{N} \sum_j x_{kj} \right)\\ \end{align*} $$