Forward propagation is the process where input data moves through a model to produce predictions. The key metrics to check here are loss and accuracy. Loss tells us how far the model's predictions are from the true answers. Accuracy shows how many predictions are correct. These metrics help us know if the model is learning well during training.
Forward propagation in ML Python - Model Metrics & Evaluation
For classification tasks, forward propagation outputs predictions that can be compared to true labels using a confusion matrix:
| Predicted Positive | Predicted Negative |
|--------------------|--------------------|
| True Positive (TP) | False Positive (FP) |
| False Negative (FN) | True Negative (TN) |
This matrix helps calculate precision, recall, and accuracy after forward propagation.
Forward propagation outputs predictions that affect precision and recall. For example, in a spam filter:
- High precision means most emails marked as spam really are spam (few good emails wrongly blocked).
- High recall means most spam emails are caught (few spam emails missed).
Depending on the task, forward propagation should produce predictions that balance these metrics well.
Good: Low loss (close to zero), high accuracy (close to 100%), balanced precision and recall.
Bad: High loss, low accuracy, very low precision or recall indicating poor prediction quality.
- Accuracy paradox: High accuracy can be misleading if classes are imbalanced.
- Data leakage: If test data leaks into training, metrics look unrealistically good.
- Overfitting: Very low training loss but high test loss means model memorizes training data, not generalizing well.
Your model has 98% accuracy but 12% recall on fraud detection. Is it good for production? Why or why not?
Answer: No, it is not good. The low recall means the model misses many fraud cases, which is risky. In fraud detection, catching as many frauds as possible (high recall) is more important than just high accuracy.
Practice
forward propagation in a neural network?Solution
Step 1: Understand forward propagation role
Forward propagation is the process where input data moves through the network layers to produce output predictions.Step 2: Differentiate from other processes
Updating weights and splitting data are separate steps, not part of forward propagation.Final Answer:
To pass input data through the network to get predictions -> Option AQuick Check:
Forward propagation = prediction step [OK]
- Confusing forward propagation with training steps
- Thinking it updates weights
- Mixing it with data preparation
Solution
Step 1: Recall neuron output formula
The neuron output is calculated by multiplying input by weight, adding bias, then applying activation.Step 2: Match formula to options
output = activation(weight * input + bias)correctly shows output = activation(weight * input + bias).Final Answer:
output = activation(weight * input + bias) -> Option DQuick Check:
Neuron output = weighted sum + bias, then activation [OK]
- Mixing order of operations
- Forgetting to apply activation function
- Using addition instead of multiplication for weights
f(x) = x (identity), what is the output after forward propagation?Solution
Step 1: Calculate weighted sum
Weighted sum = weight * input + bias = 0.5 * 4 + 1 = 2 + 1 = 3.Step 2: Apply activation function
Activation is identity, so output = 3.Final Answer:
3.0 -> Option BQuick Check:
Output = 0.5x4 + 1 = 3.0 [OK]
- Adding weight and input instead of multiplying
- Forgetting bias
- Misapplying activation function
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?Solution
Step 1: Analyze the function output
The function returns weighted sum without applying any activation function.Step 2: Understand activation role
Activation function adds non-linearity; missing it means output is raw sum, which is incomplete forward propagation.Final Answer:
The code misses applying the activation function, so output is not transformed -> Option AQuick Check:
Activation missing = incomplete forward propagation [OK]
- Thinking bias should be multiplied
- Confusing operators
- Ignoring activation importance
[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?Solution
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 = 5Step 2: Apply ReLU activation
ReLU outputs max(0, x): First neuron: max(0, 2) = 2 Second neuron: max(0, 5) = 5Step 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) = 7Final Answer:
[0, 7] -> Option CQuick Check:
Weighted sum + bias, then ReLU = [0, 7] [OK]
- Mixing weight matrix rows and columns
- Forgetting to add bias
- Applying activation before weighted sum
Ready to prove it?
Pass the test and this pattern moves unknown
