Starting from:

$30

CSC411-Homework 3 Robust Regression and Locally Weighted Regression Solved

1.    Robust Regression. One problem with linear regression using squared error loss is that it can be sensitive to outliers. Another loss function we could use is the Huber loss, parameterized by a hyperparameter δ:

if |a| ≤ δ

                                                                                             )      if |a| δ

(a)    Sketch the Huber loss Lδ(y,t) and squared error loss  for t = 0, either by hand or using a plotting library. Based on your sketch, why would you expect the Huber loss to be more robust to outliers?

(b)    Just as with linear regression, assume a linear model:

y = wx + b.

Give formulas for the partial derivatives ∂Lδ/∂w and ∂Lδ/∂b. (We recommend you find a formula for the derivative Hδ0(a), and then give your answers in terms of Hδ0(y − t).)


(c)    Write Python code to perform (full batch mode) gradient descent on this model. Assume the training dataset is given as a design matrix X and target vector y. Initialize w and b to all zeros. Your code should be vectorized, i.e. you should not have a for loop over training examples or input dimensions. You may find the function np.where helpful.


2.    Locally Weighted Regression.

(a)    Given {(x(1),y(1)),..,(x(N),y(N))} and positive weights a(1),...,a(N) show that the solution to the weighted least squares problem

                                                               w∗ = argmin             (1)

is given by the formula

                                                                                    w∗ = XTAX Ay                                   (2)

where X is the design matrix (defined in class) and A is a diagonal matrix where Aii =

a(i)

It may help you to review Section 3.1 of the csc321 notes[1].

(b)    Locally reweighted least squares combines ideas from k-NN and linear regression. For each new test example x we compute distance-based weights for each training example i , computes w∗ = argmin

 and predicts ˆy = xTw∗. Complete the implementation of locally reweighted least

squares by providing the missing parts for q2.py.

Important things to notice while implementing: First, do not invert any matrix, use a linear solver (numpy.linalg.solve is one example). Second, notice that

 but if we use B = maxj Aj it is much more numerically stable as

overflows/underflows easily. This is handled automatically in the scipy package with the scipy.misc.logsumexp function[2].

(c)    Randomly hold out 30% of the dataset as a validation set. Compute the average loss for different values of τ in the range [10,1000] on both the training set and the validation set. Plot the training and validation losses as a function of τ (using a log scale for τ).

(d)    How would you expect this algorithm to behave as τ → ∞? When τ → 0? Is this what actually happened?


More products