Question: Part 3 : Regularization In this section we will study the effect of regularization on our predictors. To do this you will need to implement

Part 3: Regularization
In this section we will study the effect of regularization on our predictors. To do this you will need to implement a regularized version of the batch gradient descent learner regularized_bgd_learner. This learner should take its gradient steps with respect to the gradient of the regularized estimated loss
\[
\hat{L_{\lambda}}(w)=\frac{1}{n}\sum_{i=1}^{n}\ell\left(x_{i}^{\top} w, y_{i}\right)+\frac{\lambda}{n}\sum_{j=1}^{d} w_{j}^{2}.
\]
For your implementation assume that the degree of the polynomial \( p \) is 1. This means you do not need to apply phi_p to the features \(\mathbf{X}\) in regularized_bgd_learner. The reason for this is that it makes the implementation simpler and it is without loss of generality since when we use your implementation to plot things we can simply apply phi_p first, before passing the features to regularized_bgd_learner.
Question 3.1
Implement regularized_bgd_learner.
Points: 12
```
def regularized_bgd_learner(X, Y, step_size=0.01, lambda_=0.1, epochs=1000, random_seed=42):
"!"
Performs batch gradient descent with L2 regularization to learn the weights.
Parameters:
X (numpy.ndarray): Feature matrix of size (n, d+1), where n is the number of samples
and d is the number of features. The first column should be all 1s.
Y (numpy.ndarray): Target vector of size (n,1).
alpha (float): Learning rate.
lambda_(float): Regularization parameter.
epochs (int): Number of iterations for gradient descent.
Returns:
predictor (function): A function that takes a feature vector and returns a predicted value.
w (numpy.ndarray): The learned weights.
"'""
n, d = X[:,1:].shape
np.random.seed(random_seed)
w = np.random.randn(d+1) # initialize the weights randomly
### YOUR CODE HERE ###
######################
def predictor(x):
return x @ w
return predictor, w
```
Part 3 : Regularization In this section we will

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!