Compiling and fitting a model

Introduction to Deep Learning in Python

Dan Becker

Data Scientist and contributor to Keras and TensorFlow libraries

Why you need to compile your model

  • Specify the optimizer
    • Many options and mathematically complex
    • "Adam" is usually a good choice
  • Loss function
    • "mean_squared_error" common for regression
Introduction to Deep Learning in Python

Compiling a model

n_cols = predictors.shape[1]
model = Sequential()
model.add(Dense(100, activation='relu', input_shape=(n_cols,)))
model.add(Dense(100, activation='relu'))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mean_squared_error')
Introduction to Deep Learning in Python

What is fitting a model

  • Applying backpropagation and gradient descent with your data to update the weights
  • Scaling data before fitting can ease optimization
Introduction to Deep Learning in Python

Fitting a model

n_cols = predictors.shape[1]
model = Sequential()
model.add(Dense(100, activation='relu', input_shape=(n_cols,)))
model.add(Dense(100, activation='relu'))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mean_squared_error')
model.fit(predictors, target)
Introduction to Deep Learning in Python

Let's practice!

Introduction to Deep Learning in Python

Preparing Video For Download...