Bird
Raised Fist0
ML Pythonml~20 mins

Forward propagation in ML Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Forward Propagation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of a simple forward propagation step
Given the following code for a single neuron forward propagation, what is the output value?
ML Python
import numpy as np

inputs = np.array([1.0, 2.0, 3.0])
weights = np.array([0.2, 0.5, -0.3])
bias = 0.1

output = np.dot(inputs, weights) + bias
print(output)
A1.8
B1.9
C0.4
D2.0
Attempts:
2 left
💡 Hint
Remember to multiply each input by its weight, sum them, then add the bias.
❓ Model Choice
intermediate
1:30remaining
Choosing the correct activation function for forward propagation
Which activation function is best suited for a binary classification problem during forward propagation?
ASoftmax
BReLU (Rectified Linear Unit)
CLinear
DSigmoid
Attempts:
2 left
💡 Hint
Think about output values between 0 and 1 representing probabilities.
❓ Hyperparameter
advanced
2:00remaining
Effect of learning rate on forward propagation outputs
If the learning rate is set too high during training, how does it affect the forward propagation outputs in subsequent iterations?
AOutputs oscillate and may not converge
BOutputs remain unchanged regardless of learning rate
COutputs become more stable and converge faster
DOutputs always decrease in value
Attempts:
2 left
💡 Hint
Consider how big steps in weight updates affect predictions.
❓ Metrics
advanced
2:00remaining
Calculating accuracy from forward propagation predictions
A model outputs the following predictions after forward propagation for 5 samples: [0.9, 0.4, 0.6, 0.3, 0.8]. The true labels are [1, 0, 1, 0, 1]. Using a threshold of 0.5, what is the accuracy?
A40%
B100%
C60%
D80%
Attempts:
2 left
💡 Hint
Convert predictions to 0 or 1 using threshold, then compare to true labels.
🔧 Debug
expert
2:30remaining
Identifying the bug in forward propagation code
What error does the following code raise during forward propagation?
ML Python
import numpy as np

def forward_prop(inputs, weights, bias):
    return np.dot(weights, inputs) + bias

inputs = np.array([1, 2, 3])
weights = np.array([0.2, 0.5])
bias = 0.1
output = forward_prop(inputs, weights, bias)
print(output)
AValueError: shapes (2,) and (3,) not aligned for dot product
BNameError: name 'np' is not defined
CTypeError: unsupported operand type(s) for +: 'int' and 'str'
DNo error, outputs a float value
Attempts:
2 left
💡 Hint
Check if input and weight arrays have matching sizes for dot product.

Practice

(1/5)
1. What is the main purpose of forward propagation in a neural network?
easy
A. To pass input data through the network to get predictions
B. To update the weights using gradients
C. To split data into training and testing sets
D. To initialize the weights randomly

Solution

  1. Step 1: Understand forward propagation role

    Forward propagation is the process where input data moves through the network layers to produce output predictions.
  2. Step 2: Differentiate from other processes

    Updating weights and splitting data are separate steps, not part of forward propagation.
  3. Final Answer:

    To pass input data through the network to get predictions -> Option A
  4. Quick Check:

    Forward propagation = prediction step [OK]
Hint: Forward propagation = input to output prediction [OK]
Common Mistakes:
  • Confusing forward propagation with training steps
  • Thinking it updates weights
  • Mixing it with data preparation
2. Which of the following is the correct formula for calculating the output of a neuron during forward propagation?
easy
A. output = input / weight - bias
B. output = weight + input * bias
C. output = activation(input - weight + bias)
D. output = activation(weight * input + bias)

Solution

  1. Step 1: Recall neuron output formula

    The neuron output is calculated by multiplying input by weight, adding bias, then applying activation.
  2. Step 2: Match formula to options

    output = activation(weight * input + bias) correctly shows output = activation(weight * input + bias).
  3. Final Answer:

    output = activation(weight * input + bias) -> Option D
  4. Quick Check:

    Neuron output = weighted sum + bias, then activation [OK]
Hint: Neuron output = activation(weight x input + bias) [OK]
Common Mistakes:
  • Mixing order of operations
  • Forgetting to apply activation function
  • Using addition instead of multiplication for weights
3. Given a single neuron with weight = 0.5, bias = 1, input = 4, and activation function f(x) = x (identity), what is the output after forward propagation?
medium
A. 3.5
B. 3.0
C. 4.0
D. 2.0

Solution

  1. Step 1: Calculate weighted sum

    Weighted sum = weight * input + bias = 0.5 * 4 + 1 = 2 + 1 = 3.
  2. Step 2: Apply activation function

    Activation is identity, so output = 3.
  3. Final Answer:

    3.0 -> Option B
  4. Quick Check:

    Output = 0.5x4 + 1 = 3.0 [OK]
Hint: Multiply weight and input, add bias, then activate [OK]
Common Mistakes:
  • Adding weight and input instead of multiplying
  • Forgetting bias
  • Misapplying activation function
4. Consider this Python code for forward propagation of a single neuron:
def forward(input, weight, bias):
    return input * weight + bias

output = forward(3, 2, 1)
print(output)
What is the error in this code if the activation function is missing?
medium
A. The code misses applying the activation function, so output is not transformed
B. The multiplication operator is wrong, should be '+' instead of '*'
C. The bias should be multiplied, not added
D. The function should return input + weight + bias instead

Solution

  1. Step 1: Analyze the function output

    The function returns weighted sum without applying any activation function.
  2. Step 2: Understand activation role

    Activation function adds non-linearity; missing it means output is raw sum, which is incomplete forward propagation.
  3. Final Answer:

    The code misses applying the activation function, so output is not transformed -> Option A
  4. Quick Check:

    Activation missing = incomplete forward propagation [OK]
Hint: Always apply activation after weighted sum [OK]
Common Mistakes:
  • Thinking bias should be multiplied
  • Confusing operators
  • Ignoring activation importance
5. You have a 2-layer neural network where the first layer outputs [2, 3] and the second layer has weights [[1, -1], [0, 2]] and biases [0, 1]. Using ReLU activation f(x) = max(0, x), what is the output of the second layer after forward propagation?
hard
A. [3, 4]
B. [2, 5]
C. [0, 7]
D. [1, 6]

Solution

  1. Step 1: Calculate weighted sums for second layer

    Multiply first layer output by weights and add biases: For first neuron: (2*1) + (3*0) + 0 = 2 + 0 + 0 = 2 For second neuron: (2*(-1)) + (3*2) + 1 = -2 + 6 + 1 = 5
  2. Step 2: Apply ReLU activation

    ReLU outputs max(0, x): First neuron: max(0, 2) = 2 Second neuron: max(0, 5) = 5
  3. Step 3: Re-check calculations for correctness

    Re-examining weights and biases: Weights matrix: [[1, -1], [0, 2]] means first output neuron weights: [1, -1] Second output neuron weights: [0, 2] Input vector: [2, 3] Calculations: Neuron 1: 2*1 + 3*(-1) + 0 = 2 - 3 + 0 = -1 Neuron 2: 2*0 + 3*2 + 1 = 0 + 6 + 1 = 7 Apply ReLU: Neuron 1: max(0, -1) = 0 Neuron 2: max(0, 7) = 7
  4. Final Answer:

    [0, 7] -> Option C
  5. Quick Check:

    Weighted sum + bias, then ReLU = [0, 7] [OK]
Hint: Multiply inputs by weights, add bias, apply ReLU [OK]
Common Mistakes:
  • Mixing weight matrix rows and columns
  • Forgetting to add bias
  • Applying activation before weighted sum
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard