程序代写 Note: An indicative mark is in front of each question. The total mark is 12

Note: An indicative mark is in front of each question. The total mark is 12. You may mark your own work when we release the solutions.
1. Figure 1 shows the COVID test results at a centre:
1) convert it to a probability table following a similar example in Lecture 6 2) calculate the observed odds of COVID positive for the age group of 20–29.
Figure 1: Age and COVID test results: 0 = negative, 1 = positive.

Copyright By PowCoder代写 加微信 powcoder

MLAI Week 6 Exercise: Logistic regression & PyTorch for deep learning
Conversion to probability table [2 marks].
0-9 10-19 20-29 30-39 40-49 50-59 60-69 70-79 80-89
Compute the odds [1 mark].
COVID Positive Group # %
1 1 100 3 2 67
7 4 57 7 5 71 5 3 60 2 2 100 1 1 100
Using the probability computed in the table above for the 20-29 age group of 23 , we can compute the odds as follows:

Odds= π 1−π
2 2. Derive π from log π = w⊤x (slide 22), i.e. derive the logistic function from the logit 1−π
starting at the expression of the logit function,
log 1−π =w x (2)
taking the exponent of both sides
π =ewTx (3) 1−π =e−wTx
π1 − 1 = e − w T x
π1 = 1 + e − w T x
2 3. The last equation on slide 23 writes the log likelihood in terms of πi. Rewrite the equation in terms of the weight vector w and input vector x.
logP(y | X) = = =
􏰆logP(yi | xi) (5)
􏰆n􏰃1􏰄􏰆n 􏰃1􏰄
yi log 1+e−wTx + (1−yi)log 1− 1+e−wTx (6) ii
􏰆 􏰃 1 􏰄􏰆 1+e−wxi−1
yi log 1 + e−wTx + (1 − yi) log 1 + e−wTx (7) ii

􏰆n􏰃1􏰄􏰆n 􏰃1􏰄
log P (y | X) = yi log 1 + e−wTx i=1
+ (1 − yi) log ewTx + 1 (8) i=1
In a binary (two-class) logistic regression model, the weight vector w = [4, -2, 5, -3, 11, 9]. We apply it to some object that we’d like to classify; the vectorized feature representation of this object is x = [6, 8, 2, 7, -3, 5]. What is the probability, according to the model, that this instance belongs to the positive class?
We can compute this probability using the following expression,
P(y = 1|x) = 1 . (9) 1 + e−wTx
This first requires computation of wTx, which in this case is,
wTx = (4 × 6) + (−2 × 8) + (5 × 2) + (−3 × 7) + (11 × −3) + (9 × 5)
We can then substitute this value into (9) to obtain the final answer (given to 5 signif- icant figures),
P(y = 1|x) = 1
1 + e−9 (11)
= 0.99988.
Consider the fully connected neural network (multilayer perceptron) on slide 33. If we insert two new hidden layers between the old Hidden Layer (4 neurons) and the Output Layer (2 neurons), i.e., 1 (6 neurons) after old Hidden layer, 2 ( 5 neurons) after New layer 1, and Output Layer after 2, with full connections between all adjacent layers and no other connections. The same activation function sigma (sigmoid) is used in the new hidden layers. How many learnable parameters in total are there for this three-hidden-layer neural network?
The neural network described in the question has the following structure:

Input Hidden Hidden Hidden Output Layer 1 Layer 2 Layer 3
Firstly we must count all of the weights which connect the layers of our model,
Number of weights = (3 × 4) + (4 × 6) + (6 × 5) + (5 × 2) = 76.
Next, we count up all of the bias parameters,
Number of biases = 4 + 6 + 5 + 2
The sum of these two values is the total number of model parameters, therefore the answer is 76 + 17 = 93.