Get startedGet started for free

Compiling the model

You're now going to compile the model you specified earlier. To compile the model, you need to specify the optimizer and loss function to use. In the video, Dan mentioned that the Adam optimizer is an excellent choice. You can read more about it as well as other Keras optimizers here, and if you are really curious to learn more, you can read the original paper that introduced the Adam optimizer.

In this exercise, you'll use the Adam optimizer and the mean squared error loss function. Go for it!

This exercise is part of the course

Introduction to Deep Learning in Python

View Course

Exercise instructions

  • Compile the model using model.compile(). Your optimizer should be 'adam' and the loss should be 'mean_squared_error'.

Hands-on interactive exercise

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

# Import necessary modules
from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Sequential

# Specify the model
n_cols = predictors.shape[1]
model = Sequential()
model.add(Dense(50, activation='relu', input_shape = (n_cols,)))
model.add(Dense(32, activation='relu'))
model.add(Dense(1))

# Compile the model
____

# Verify that model contains information from compiling
print("Loss function: " + model.loss)
Edit and Run Code