Deep Learning Intro
- 26Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
How can logistic regression be interpreted as a neural network?
26 questions
- 1
How can logistic regression be interpreted as a neural network?
Model answer
Logistic regression can be interpreted as a single neuron with a linear part wTx+b followed by a sigmoid activation function, making it a one-neuron neural network.
Explanation
The lecture defines a neuron as linear plus activation, and logistic regression fits that structure exactly, with the sigmoid as the activation.
- 2
For a 64x64 color image, what is the size of the flattened input vector x?
Model answer
The flattened vector has dimension 64×64×3=12,288.
Explanation
Each pixel has three RGB values, so total numbers = height * width * channels.
- 3
In logistic regression for cat detection, if the input vector x has shape n×1, what are the shapes of w and b such that y^=σ(wTx+b) is a scalar?
Model answer
w is 1×n (row vector), b is 1×1 (scalar), so wTx+b is a scalar.
Explanation
To get a scalar output, w must have dimensions 1×n and b a scalar.
- 4
How many parameters (weights and biases) does a logistic regression model have for a 64x64 color image?
Model answer
12,288 weights (since input size is 12,288) and 1 bias, giving 12,289 total parameters.
Explanation
Number of weights equals input size, plus one bias.
- 5
What is the formula for logistic regression’s loss function (binary cross-entropy) for a single example?
Model answer
L(y^,y)=−(ylogy^+(1−y)log(1−y^))
Explanation
This loss is derived from maximum likelihood estimation and penalizes deviation between predicted probability and true label.
- 6
Explain the two steps of the training process for logistic regression as described in the lecture.
Model answer
First, initialize parameters w and b. Then, repeatedly compute gradients of the loss and update parameters using gradient descent to minimize the loss.
Explanation
The process is: initialize, then loop over gradient descent steps until convergence.
- 7
If you want to classify images into three classes (cat, lion, iguana) with the possibility of multiple animals in one image, what output activation should you use and why?
Model answer
Use three separate sigmoid neurons (one per class) because sigmoid outputs independent probabilities for each class, allowing multiple classes to be present.
Explanation
Sigmoid gives independent probabilities; the three outputs do not sum to 1, so multiple can be high simultaneously.
- 8
What is the softmax function formula for class i given three neurons with linear outputs z1,z2,z3?
Model answer
y^i=∑k=13ezkezi
Explanation
Softmax converts the z values into a probability distribution that sums to 1.
- 9
Why is a network with three sigmoid neurons not suitable when the labels are one-hot (only one class per image)?
Model answer
The sigmoid outputs can sum to more than 1, but the labels sum to 1; the network would need to learn to output probabilities that sum to 1, but sigmoid does not enforce that, leading to inconsistent predictions.
Explanation
For mutually exclusive classes, softmax is preferred because it naturally produces a valid probability distribution.
- 10
How many parameters does the three-neuron sigmoid network (for three classes) have if the input dimension is n?
Model answer
Each neuron has n weights and 1 bias, so total parameters = 3n+3.
Explanation
Three neurons, each with a weight vector of size n and a bias, hence 3n+3.
- 11
Write the loss function for the three-neuron sigmoid multi-class network (assuming one-hot labels) and explain why it can be viewed as three separate logistic regressions.
Model answer
L=−∑k=13(yklogy^k+(1−yk)log(1−y^k)). The gradient for each neuron’s parameters depends only on that neuron’s output, so they can be trained independently.
Explanation
The loss is the sum of independent binary cross-entropy losses; derivatives for each neuron are unaffected by the others.
- 12
For a regression task (e.g., predicting cat age), what changes would you make to the logistic regression model?
Model answer
Replace the sigmoid activation with a linear or ReLU activation (to allow outputs beyond 0-1) and change the loss to L2 loss or mean squared error.
Explanation
Age is a continuous positive value; linear activation (or ReLU to enforce non-negativity) and MSE loss are appropriate.
- 13
In a neural network with one hidden layer of size 3 and an input of size n, what is the shape of the weight matrix W[1] connecting the input to the hidden layer?
Model answer
W[1] has shape 3×n (3 neurons in hidden layer, n input features).
Explanation
Each hidden neuron has n weights, so total weights form a 3×n matrix.
- 14
Define the terms: input layer, hidden layer, output layer.
Model answer
Input layer: the first layer that receives raw data. Hidden layer: any layer between input and output; its neurons do not directly see inputs or outputs. Output layer: the final layer that produces the prediction.
Explanation
Hidden layers learn intermediate representations; output layer size equals number of classes or 1 for regression.
- 15
Why are neural networks sometimes called 'black box' models?
Model answer
Because the internal representations learned by hidden layers (e.g., which features each neuron detects) are not easily interpretable by humans, even though the network may perform well.
Explanation
The learned features are often abstract and not directly understandable, leading to the black box characterization.
- 16
For a neural network with input size n, hidden layer size h, and output size o, how many parameters are there if the network is fully connected?
Model answer
(n×h+h) for the first layer plus (h×o+o) for the second, total nh+h+ho+o.
Explanation
Each connection is a weight, each neuron has a bias. Count edges plus biases per layer.
- 17
Write the forward propagation equations for a 3-layer neural network (input, hidden, output) with sigmoid activations, using matrix notation.
Model answer
Z[1]=W[1]X+b[1], A[1]=σ(Z[1]), Z[2]=W[2]A[1]+b[2], A[2]=σ(Z[2]), Z[3]=W[3]A[2]+b[3], y^=σ(Z[3]).
Explanation
This shows matrix multiplications and element-wise sigmoid for each layer.
- 18
Explain why broadcasting is needed when implementing forward propagation with a batch of m examples.
Model answer
When adding bias b, which has shape (nl,1), to the matrix WX of shape (nl,m), broadcasting replicates the bias m times to match dimensions, enabling parallel computation without increasing parameters.
Explanation
Broadcasting allows element-wise addition between matrices of different shapes by repeating the smaller matrix.
- 19
What are the shapes of Z[1], W[1], X, and b[1] when processing a batch of m examples with n features and a hidden layer of size h?
Model answer
X: (n,m), W[1]: (h,n), b[1]: (h,1), Z[1]: (h,m).
Explanation
Matrix multiplication W[1]X produces (h,m); adding bias broadcasts to the same shape.
- 20
What is the key idea behind backpropagation?
Model answer
Backpropagation uses the chain rule of calculus to efficiently compute gradients of the loss with respect to all parameters by propagating errors from the output layer backward through the network.
Explanation
Gradients are computed layer by layer from output to input, reusing previously computed values to avoid redundant calculations.
- 21
When computing the gradient ∂W[2]∂J, why is it easier to start with ∂Z[2]∂J?
Model answer
Because Z[2] is directly related to W[2] (Z[2]=W[2]A[1]+b[2]), and the derivative ∂W[2]∂Z[2]=A[1]T is simple, while J depends on W[2] only through Z[2].
Explanation
Chain rule: ∂W[2]∂J=∂Z[2]∂J∂W[2]∂Z[2], and the latter is easy to compute.
- 22
How does the derivative of the sigmoid function simplify calculations in backpropagation?
Model answer
The derivative of sigmoid is σ(z)(1−σ(z)), which can be expressed in terms of the activation a=σ(z): dzdσ=a(1−a), making it easy to compute from forward pass values.
Explanation
This allows reuse of stored activations to compute gradients efficiently.
- 23
Explain the practical difference between stochastic gradient descent (SGD) and batch gradient descent.
Model answer
SGD updates parameters after each single example, leading to noisy gradients but faster iterations. Batch gradient descent computes the gradient over the entire dataset, giving a more accurate direction but slower per iteration.
Explanation
The lecture notes that SGD gradient is noisier; batch gradient uses the average gradient over all examples.
- 24
How would you choose the number of layers and neurons for a neural network in practice?
Model answer
Try several architectures, train them, and compare validation set accuracies; the best performing architecture is selected. Experience and problem complexity also guide choices (more complex problems often need deeper networks).
Explanation
Hyperparameter tuning via validation set is standard; heuristics suggest deeper networks for harder tasks.
- 25
What does 'end-to-end learning' mean in the context of neural networks?
Model answer
End-to-end learning means training a neural network directly from raw input to desired output without manually engineered intermediate features; the network learns all necessary representations.
Explanation
The lecture contrasts this with hand-engineering features; the network learns from input-output pairs alone.
- 26
For a dataset where each image contains at most one of three animal types (cat, lion, iguana), which output activation and loss function should be used?
Model answer
Use softmax activation (to produce a probability distribution summing to 1) and cross-entropy loss L=−∑k=13yklogy^k.
Explanation
Softmax enforces mutual exclusivity; cross-entropy is the standard loss for multi-class classification.

Ask anything
We've read this whole study set, so questions about it get the best answers.