Get startedGet started for free

Training neural networks with TensorFlow

In the previous exercise, you defined a model, model(w1, b1, w2, b2, features), and a loss function, loss_function(w1, b1, w2, b2, features, targets), both of which are available to you in this exercise. You will now train the model and then evaluate its performance by predicting default outcomes in a test set, which consists of test_features and test_targets and is available to you. The trainable variables are w1, b1, w2, and b2. Additionally, the following operations have been imported for you: keras.activations.relu() and keras.layers.Dropout().

This exercise is part of the course

Introduction to TensorFlow in Python

View Course

Exercise instructions

  • Set the optimizer to perform minimization.
  • Add the four trainable variables to var_list in the order in which they appear as arguments to loss_function().
  • Use the model and test_features to predict the values for test_targets.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Train the model
for j in range(100):
    # Complete the optimizer
	opt.____(lambda: loss_function(w1, b1, w2, b2), 
                 var_list=[____, ____, ____, ____])

# Make predictions with model using test features
model_predictions = model(w1, b1, w2, b2, ____)

# Construct the confusion matrix
confusion_matrix(test_targets, model_predictions)
Edit and Run Code