Skip to content

Instantly share code, notes, and snippets.

@esenthil2018
Created May 28, 2022 03:43
Show Gist options
  • Save esenthil2018/4ee466d1ef11163ebd78633c0a3a5fe5 to your computer and use it in GitHub Desktop.
Save esenthil2018/4ee466d1ef11163ebd78633c0a3a5fe5 to your computer and use it in GitHub Desktop.
#Linear regression Model
linear_model = tf.keras.Sequential([
normalizer,
layers.Dense(units=1)
])
linear_model.predict(train_features1[:10])
linear_model.layers[1].kernel
linear_model.compile(
optimizer=tf.optimizers.Adam(learning_rate=0.1),
loss='mean_absolute_error')
history = linear_model.fit(
train_features1,
train_labels1,
epochs=100,
# Suppress logging.
verbose=0,
# Calculate validation results on 20% of the training data.
validation_split = 0.2)
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 = {}
test_results['linear_model'] = linear_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