Coding the forward propagation algorithm
In this exercise, you'll write code to do forward propagation (prediction) for your first neural network:
Each data point is a customer. The first input is how many accounts they have, and the second input is how many children they have. The model will predict how many transactions the user makes in the next year. You will use this data throughout the first 2 chapters of this course.
The input data has been pre-loaded as input_data
, and the weights are available in a dictionary called weights
. The array of weights for the first node in the hidden layer are in weights['node_0']
,
and the array of weights for the second node in the hidden layer are in weights['node_1']
.
The weights feeding into the output node are available in weights['output']
.
NumPy will be pre-imported for you as np
in all exercises.
This exercise is part of the course
Introduction to Deep Learning in Python
Exercise instructions
- Calculate the value in node 0 by multiplying
input_data
by its weightsweights['node_0']
and computing their sum. This is the 1st node in the hidden layer. - Calculate the value in node 1 using
input_data
andweights['node_1']
. This is the 2nd node in the hidden layer. - Put the hidden layer values into an array. This has been done for you.
- Generate the prediction by multiplying
hidden_layer_outputs
byweights['output']
and computing their sum. - Hit 'Submit Answer' to print the output!
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Calculate node 0 value: node_0_value
node_0_value = (____ * ____).____
# Calculate node 1 value: node_1_value
node_1_value = ____
# Put node values into array: hidden_layer_outputs
hidden_layer_outputs = np.array([node_0_value, node_1_value])
# Calculate output: output
output = ____
# Print output
print(output)