Python机器学习代写 | COMP9417 Homework 1: Linear Regression & Friends

本次澳洲代写主要为python机器学习相关的homework

Question 1. Simple Linear Regression
(a) Consider a data set consisting ofX values (features)X1; : : : ;Xn and Y values (responses) Y1; : : : ; Yn.
Let ^ 0; ^ 1; ^  be the output of running ordinary least squares (OLS) regression on the data. Now
define the transformation:
e Xi = c(Xi + d);
for each i = 1; : : : ; n, where c = 0 and d are arbitrary real constants. Let e 0; e 1; e  be the output of
OLS on the data e X1; : : : ; e Xn and Y1; : : : ; Yn. Write equations for e 0; e 1; e  in terms of ^ 0; ^ 1; ^  (and
in terms of c; d), and be sure to justify your answers. Note that the estimate of error in OLS is taken
to be:
^  =
s
^ eT ^ e
n p
;

where ^ e is the vector of residuals, i.e. with i-the element ^ ei = Yi ^ Yi, where ^ Yi is the i-th prediction
made by the model, and p is the number of features (so in this case p = 2).
(b) Suppose you have a dataset where X takes only two values while Y can take arbitrary real values.
To consider a concrete example, consider a clinical trial where Xi = 1 indicates that the i-th patient
receives a dose of a particular drug (the treatment), and Xi = 0 indicates that they did not, and
Yi is the real-valued outcome for the i-th patient, e.g. blood pressure. Let Y T and Y P indicate the
sample mean outcomes for the treatment group and non-treatment (placebo) group, respectively.
What will be the value of the OLS coefficients ^ 0; ^ 1 in terms of the group means?
What to submit: For both parts of the question, present your solution neatly – photos of handwritten work or
using a tablet to write the answers is fine. Please include all working and circle your final answers.
Question 2. LASSO vs. Ridge Regression
In this problem we will consider the dataset provided in data.csv, with response variable Y , and
features X1; : : : ;X8.

(a) Use a pairs plot to study the correlations between the features. In 3-4 sentences, describe what
you see and how this might affect a linear regression model. What to submit: a single plot, some
commentary.

(b) In order for LASSO and Ridge to be run properly, we often rescale the features in the dataset. First,
rescale each feature so that it has zero mean, and then rescale it so that
Pn
i=1 X2
ij = n where n
denotes the total number of observations. What to submit: print out the sum of squared observations of
each of the 8 (transformed) features, i.e.
Pi
X2
ij for j = 1; : : : ; 8
(c) Now we will apply ridge regression to this dataset, recall that ridge regression is defined as the
solution to the optimisation:
^ = argmin
1
2
kY X k2
2 + k k2
2

:
Run ridge regression with  = f0:01; 0:1; 0:5; 1; 1:5; 2; 5; 10; 20; 30; 50; 100; 200; 300g. Create a plot
with x-axis representing log(), and y-axis representing the value of the coefficient for each feature
in each of the fitted ridge models. In other words, the plot should describe what happens to each
of the coefficients in your model for the different choices of . For this problem you are permitted