Skip to content

Instantly share code, notes, and snippets.

@KenoLeon
Last active July 17, 2020 20:48
Show Gist options
  • Select an option

  • Save KenoLeon/a5ab55414dac01d63f4e2079296f1730 to your computer and use it in GitHub Desktop.

Select an option

Save KenoLeon/a5ab55414dac01d63f4e2079296f1730 to your computer and use it in GitHub Desktop.
Build keras model
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
def build_model(learning_rate, layer_size):
"""Build Keras model"""
model = keras.Sequential([
layers.Dense(layer_size, activation='relu',
input_shape=[len(feature_names)]),
layers.Dense(layer_size, activation='relu', kernel_regularizer='l2'),
layers.Dense(1, activation='sigmoid')
])
optimizer = tf.keras.optimizers.Adam(learning_rate=learning_rate)
model.compile(loss='mse', optimizer=optimizer, metrics=['mae', 'mse'])
return model
# Later called by:
regressor_model = build_model(lr, layer_Size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment