1. Homepage
  2. Programming
  3. COMP9417 - Machine Learning Homework 2: Bias, Variance and an application of Gradient Descent

COMP9417 - Machine Learning Homework 2: Bias, Variance and an application of Gradient Descent

Engage in a Conversation
UNSWCOMP9417Machine LearningPythonBiasVarianceGradient Descent

COMP9417 - Machine Learning
Homework 2: Bias, Variance and an application of Gradient Descent
CourseNana.COM

Introduction In this homework we revisit the notion of bias and variance as metrics for characterizing the behaviour of an estimator. We then take a look at a new gradient descent based algorithm for combining different machine learning models into a single, more complex, model CourseNana.COM

  • A single PDF file which contains solutions to each question. For each question, provide your solution in the form of text and requested plots. For some questions you will be requested to provide screen shots of code used to generate your answer — only include these when they are explicitly asked for. CourseNana.COM

  • .py file(s) containing all code you used for the project, which should be provided in a separate .zip file. This code must match the code provided in the report. CourseNana.COM

  • You may be deducted points for not following these instructions. CourseNana.COM

  • You may be deducted points for poorly presented/formatted work. Please be neat and make your solutions clear. Start each question on a new page if necessary. CourseNana.COM

  • You cannot submit a Jupyter notebook; this will receive a mark of zero. This does not stop you from developing your code in a notebook and then copying it into a .py file though, or using a tool such as nbconvert or similar. CourseNana.COM

  • We will set up a Moodle forum for questions about this homework. Please read the existing questions before posting new questions. Please do some basic research online before posting questions. Please only post clarification questions. Any questions deemed to be fishing for answers will be ignored and/or deleted. CourseNana.COM

  • Please check Moodle announcements for updates to this spec. It is your responsibility to check for announcements about the spec. CourseNana.COM

  • Please complete your homework on your own, do not discuss your solution with other people in the course. General discussion of the problems is fine, but you must write out your own solution and acknowledge if you discussed any of the problems in your submission (including their name(s) and zID). CourseNana.COM

  • As usual, we monitor all online forums such as Chegg, StackExchange, etc. Posting homework ques- tions on these site is equivalent to plagiarism and will result in a case of academic misconduct. CourseNana.COM

  • You may not use SymPy or any other symbolic programming toolkits to answer the derivation ques- tions. This will result in an automatic grade of zero for the relevant question. You must do the derivations manually. CourseNana.COM

    When and Where to Submit CourseNana.COM

  • Due date: Week 5, Friday June 28th, 2024 by 5pm. Please note that the forum will not be actively monitored on weekends. CourseNana.COM

  • Late submissions will incur a penalty of 5% per day from the maximum achievable grade. For ex- ample, if you achieve a grade of 80/100 but you submitted 3 days late, then your final grade will be 80 3 × 5 = 65. Submissions that are more than 5 days late will receive a mark of zero. CourseNana.COM

  • Submission must be made on Moodle, no exceptions. CourseNana.COM

Question 1. Bias of Estimators CourseNana.COM

Let γ > 0 and suppose that X1,...,Xn CourseNana.COM

i.i.d. 2
N(γ,γ ). We define: CourseNana.COM

S2 = n1 You may use the following two facts without proof: CourseNana.COM

(F1) X and S2 are independent.
(F2)
X and cS are both unbiased estimators of γ.1 CourseNana.COM

1 Xn X=n Xi, CourseNana.COM

i=1
1 Xn CourseNana.COM

(Xi X)2. CourseNana.COM

What to submit: for all parts (a)-(e), include your working out, either typed or handwritten. For all parts, you must show all working for full credit. Answers without working will receive a grade of zero. CourseNana.COM

  1. (a)  Consider the estimator: CourseNana.COM

    T1 =aX+(1a)cS. Show that for any choice of constant a, T1 is unbiased for γ. CourseNana.COM

  2. (b)  What choice of a gives you the best (in the sense of MSE) possible estimator? Derive an explicit expression for this optimal choice of a. We refer to this estimator as T1. CourseNana.COM

  3. (c)  Consider now a different estimator: CourseNana.COM

    T 2 = a 1 X ̄ + a 2 ( c S ) , CourseNana.COM

    and we do not make any assumptions about the relationship between a1 and a2. Find the con- stants a1 , a2 explicitly that make T2 best (from the MSE perspective), i.e. choose a1 , a2 to minimize MSE(T2) = E(T2 γ)2. We refer to this estimator as T2. CourseNana.COM

  4. (d)  Show that T2has MSE that is less than or equal to the MSE of T1. CourseNana.COM

  5. (e)  Consider the estimator V+ = max{0, T2}. Show that the MSE of V+ is smaller than or equal to the CourseNana.COM

    MSE of T2. CourseNana.COM

Question 2. Gradient Descent for Learning Combinations of Models CourseNana.COM

In this question, we discuss and implement a gradient descent based algorithm for learning combina- tions of models, which are generally termed ’ensemble models’. The gradient descent idea is a very powerful one that has been used in a large number of creative ways in machine learning beyond direct minimization of loss functions. CourseNana.COM

The Gradient-Combination (GC) algorithm can be described as follows: Let F be a set of base learning algorithms2. The idea is to combine the base learners in F in an optimal way to end up with a good learning algorithm. Let l(y, yˆ) be a loss function, where y is the target, and yˆ is the predicted value.3 Suppose we have data (xi, yi) for i = 1, . . . , n, which we collect into a single data set D0. We then set the number of desired base learners to T and proceed as follows: CourseNana.COM

1You do not need to worry about knowing or calculating cfor this question, it is just some constant. CourseNana.COM

2For example, you could take F to be the set of all regression models with a single feature, or alternatively the set of all regression models with 4 features, or the set of neural networks with 2 layers etc. CourseNana.COM

3Note that this set-up is general enough to include both regression and classification algorithms. CourseNana.COM

Page 3 CourseNana.COM

(I) Initialize f0(x) = 0 (i.e. f0 is the zero function.) (II) For t = 1,2,...,T: CourseNana.COM

(GC1) Compute: CourseNana.COM

Xn
rt,i = ∂f(xi) l(yj,f(xj)) CourseNana.COM

j=1 CourseNana.COM

f(xj)=ft1(xj), j=1,...,n CourseNana.COM

for i = 1, . . . , n. We refer to rt,i as the i-th pseudo-residual at iteration t. CourseNana.COM

  1. (GC2)  Constructanewpseudodataset,Dt,consistingofpairs:(xi,rt,i)fori=1,...,n. CourseNana.COM

  2. (GC3)  Fit a model to Dt using our base class F. That is, we solve CourseNana.COM

    n CourseNana.COM

    ht =argminXl(rt,i,f(xi)) CourseNana.COM

    f∈F
    i=1 CourseNana.COM

  3. (GC4)  Choose a step-size. This can be done by either of the following methods: CourseNana.COM

(SS1) Pick a fixed step-size αt = α
(SS2) Pick a step-size adaptively according to CourseNana.COM

(GC5) Take the step (III) return fT . CourseNana.COM

n CourseNana.COM

αt =argminXl(yi,ft1(xi)+αht(xi)). CourseNana.COM

α
i
=1 CourseNana.COM

ft(x) = ft1(x) + αtht(x). CourseNana.COM

We can view this algorithm as performing (functional) gradient descent on the base class F. Note that in (GC1), the notation means that after taking the derivative with respect to f(xi), set all occurences of f(xj) in the resulting expression with the prediction of the current model ft1(xj), for all j. For example: CourseNana.COM

log(x+1) = 1 = 1. ∂x x=23 x+1 x=23 24 CourseNana.COM

  1. (a)  Consider the regression setting where we allow the y-values in our data set to be real numbers. Suppose that we use squared error loss l(y, yˆ) = 21 (y yˆ)2. For round t of the algorithm, show that rt,i = yi ft1(xi). Then, write down an expression for the optimization problem in step (GC3) that is specific to this setting (you don’t need to actually solve it). CourseNana.COM

    What to submit: your working out, either typed or handwritten. CourseNana.COM

  2. (b)  Using the same setting as in the previous part, derive the step-size expression according to the adaptive approach (SS2).
    What to submit: your working out, either typed or handwritten. CourseNana.COM

  3. (c)  We will now implement the gradient-combination algorithm on a toy dataset from scratch, and we will use the class of decision stumps (depth 1 decision trees) as our base class (F ), and squared error loss as in the previous parts.4. The following code generates the data and demonstrates plotting the predictions of a fitted decision tree (more details in q1.py): CourseNana.COM

4In your implementation, you may make use of sklearn.tree.DecisionTreeRegressor, but all other code must be your own. You may use NumPy and matplotlib, but do not use an existing implementation of the algorithm if you happen to find one. CourseNana.COM

Page 4 CourseNana.COM

np.random.seed(123)
X, y = f_sampler(f, 160, sigma=0.2)
X = X.reshape(-1,1)
fig = plt.figure(figsize=(7,7))
dt = DecisionTreeRegressor(max_depth=2).fit(X,y)              # example model
xx = np.linspace(0,1,1000)
plt.plot(xx, f(xx), alpha=0.5, color=’red’, label=’truth’)
plt.scatter(X,y, marker=’x’, color=’blue’, label=’observed’)
plt.plot(xx, dt.predict(xx.reshape(-1,1)), color=’green’, label=’dt’)  # plotting
example model
plt.legend()
plt.show()
The figure generated is

Your task is to generate a 5 x 2 figure of subplots showing the predictions of your fitted gradient- combination model. There are 10 subplots in total, the first should show the model with 5 base learners, the second subplot should show it with 10 base learners, etc. The last subplot should be the gradient-combination model with 50 base learners. Each subplot should include the scatter of data, as well as a plot of the true model (basically, the same as the plot provided above but with your fitted model in place of dt). Comment on your results, what happens as the number of base learners is increased? You should do this two times (two 5x2 plots), once with the adaptive step size, and the other with the step-size taken to be α = 0.1 fixed throughout. There is no need to split into train and test data here. Comment on the differences between your fixed and adaptive step-size implementations. How does your model perform on the different x-ranges of the data? What to submit: two 5 x 2 plots, one for adaptive and one for fixed step size, some commentary, and a screen shot of your code and a copy of your code in your .py file. CourseNana.COM

CourseNana.COM

  1. (d)  Repeat the analysis in the previous question but with depth 2 decision trees as base learners in- stead. Provide the same plots. What do you notice for the adaptive case? What about the non- adaptive case? What to submit: two 5 x 2 plots, one for adaptive and one for fixed step size, some commen- tary, and a copy of your code in your .py file. CourseNana.COM

  2. (e)  Now, consider the classification setting where y is taken to be an element of {−1, 1}. We consider the following classification loss: l(y, yˆ) = log(1 + eyyˆ). For round t of the algorithm, what is the expression for rt,i? Write down an expression for the optimization problem in step (GC3) that is specific to this setting (you don’t need to actually solve it). CourseNana.COM

    What to submit: your working out, either typed or handwritten. CourseNana.COM

  3. (f)  Using the same setting as in the previous part, write down an expression for αt using the adaptive approach in (SS2). Can you solve for αt in closed form? Explain.
    What to submit: your working out, either typed or handwritten, and some commentary. CourseNana.COM

  4. (g)  In practice, if you cannot solve for αt exactly, explain how you might implement the algorithm. Assume that using a constant step-size is not a valid alternative. Be as specific as possible in your answer. What, if any, are the additional computational costs of your approach relative to using a constant step size ? CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
UNSW代写,COMP9417代写,Machine Learning代写,Python代写,Bias代写,Variance代写,Gradient Descent代写,UNSW代编,COMP9417代编,Machine Learning代编,Python代编,Bias代编,Variance代编,Gradient Descent代编,UNSW代考,COMP9417代考,Machine Learning代考,Python代考,Bias代考,Variance代考,Gradient Descent代考,UNSWhelp,COMP9417help,Machine Learninghelp,Pythonhelp,Biashelp,Variancehelp,Gradient Descenthelp,UNSW作业代写,COMP9417作业代写,Machine Learning作业代写,Python作业代写,Bias作业代写,Variance作业代写,Gradient Descent作业代写,UNSW编程代写,COMP9417编程代写,Machine Learning编程代写,Python编程代写,Bias编程代写,Variance编程代写,Gradient Descent编程代写,UNSWprogramming help,COMP9417programming help,Machine Learningprogramming help,Pythonprogramming help,Biasprogramming help,Varianceprogramming help,Gradient Descentprogramming help,UNSWassignment help,COMP9417assignment help,Machine Learningassignment help,Pythonassignment help,Biasassignment help,Varianceassignment help,Gradient Descentassignment help,UNSWsolution,COMP9417solution,Machine Learningsolution,Pythonsolution,Biassolution,Variancesolution,Gradient Descentsolution,