Skip to content

Instantly share code, notes, and snippets.

@esenthil2018
Created May 28, 2022 03:47
Show Gist options
  • Save esenthil2018/9d045b0e10a49cc6347a2825eb3def6c to your computer and use it in GitHub Desktop.
Save esenthil2018/9d045b0e10a49cc6347a2825eb3def6c to your computer and use it in GitHub Desktop.
#DNN Model
def build_and_compile_model(norm):
model = keras.Sequential([
norm,
layers.Dense(64, activation='relu'),
layers.Dense(64, activation='relu'),
layers.Dense(1)
])
model.compile(loss='mean_absolute_error',
optimizer=tf.keras.optimizers.Adam(0.001))
return model
dnn_model = build_and_compile_model(normalizer)
dnn_model.summary()
history = dnn_model.fit(
train_features1,
train_labels1,
validation_split=0.2,
verbose=0, epochs=100)
def plot_loss(history):
plt.plot(history.history['loss'], label='loss')
plt.plot(history.history['val_loss'], label='val_loss')
plt.ylim([0, 10])
plt.xlabel('Epoch')
plt.ylabel('Error [MPG]')
plt.legend()
plt.grid(True)
plot_loss(history)
test_results['dnn_model'] = dnn_model.evaluate(test_features1, test_labels1, verbose=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment