Applying the network to many observations/rows of data
You'll now define a function called predict_with_network()
which will generate predictions for multiple data observations, which are pre-loaded as input_data
. As before, weights
are also pre-loaded. In addition, the relu()
function you defined in the previous exercise has been pre-loaded.
This exercise is part of the course
Introduction to Deep Learning in Python
Exercise instructions
- Define a function called
predict_with_network()
that accepts two arguments -input_data_row
andweights
- and returns a prediction from the network as the output. - Calculate the input and output values for each node, storing them as:
node_0_input
,node_0_output
,node_1_input
, andnode_1_output
.- To calculate the input value of a node, multiply the relevant arrays together and compute their sum.
- To calculate the output value of a node, apply the
relu()
function to the input value of the node.
- Calculate the model output by calculating
input_to_final_layer
andmodel_output
in the same way you calculated the input and output values for the nodes. - Use a
for
loop to iterate overinput_data
:- Use your
predict_with_network()
to generate predictions for each row of theinput_data
-input_data_row
. Append each prediction toresults
.
- Use your
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define predict_with_network()
def predict_with_network(input_data_row, weights):
# Calculate node 0 value
node_0_input = ____
node_0_output = ____
# Calculate node 1 value
node_1_input = ____
node_1_output = ____
# Put node values into array: hidden_layer_outputs
hidden_layer_outputs = np.array([node_0_output, node_1_output])
# Calculate model output
input_to_final_layer = ____
model_output = ____
# Return model output
return(model_output)
# Create empty list to store prediction results
results = []
for input_data_row in input_data:
# Append prediction to results
results.append(____)
# Print results
print(results)