Skip to content

Instantly share code, notes, and snippets.

@securetorobert
Created January 14, 2019 07:10
Show Gist options
  • Save securetorobert/fef5993cb68afb56fe2bddd7aa948a32 to your computer and use it in GitHub Desktop.
Save securetorobert/fef5993cb68afb56fe2bddd7aa948a32 to your computer and use it in GitHub Desktop.
Simple Keras Model with l1_l2 regularization
import tensorflow as tf
from tensorflow import keras
model = keras.models.Sequential([
keras.layers.Dense(4, activation=tf.nn.relu, input_shape=(4,), kernel_regularizer=keras.regularizers.l1_l2(l1=0.1, l2=0.01)),
keras.layers.Dense(4, activation=tf.nn.relu, kernel_regularizer=keras.regularizers.l1_l2(l1=0.1, l2=0.01)),
keras.layers.Dense(1, activation=tf.nn.sigmoid)
])
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment