Defining the model and loss function
In this exercise, you will train a neural network to predict whether a credit card holder will default. The features and targets you will use to train your network are available in the Python shell as borrower_features
and default
. You defined the weights and biases in the previous exercise.
Note that the predictions
layer is defined as \(\sigma(layer1*w2+b2)\), where \(\sigma\) is the sigmoid activation, layer1
is a tensor of nodes for the first hidden dense layer, w2
is a tensor of weights, and b2
is the bias tensor.
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
Exercise instructions
- Apply a rectified linear unit activation function to the first layer.
- Apply 25% dropout to
layer1
. - Pass the target,
targets
, and the predicted values,predictions
, to the cross entropy loss function.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define the model
def model(w1, b1, w2, b2, features = borrower_features):
# Apply relu activation functions to layer 1
layer1 = keras.activations.____(matmul(features, w1) + b1)
# Apply dropout rate of 0.25
dropout = keras.layers.Dropout(____)(____)
return keras.activations.sigmoid(matmul(dropout, w2) + b2)
# Define the loss function
def loss_function(w1, b1, w2, b2, features = borrower_features, targets = default):
predictions = model(w1, b1, w2, b2)
# Pass targets and predictions to the cross entropy loss
return keras.losses.binary_crossentropy(____, ____)