Skip to content

Instantly share code, notes, and snippets.

@edunuke
Last active April 26, 2019 09:51
Show Gist options
  • Select an option

  • Save edunuke/4c8eb8b11065b3d78d0424371df79ed8 to your computer and use it in GitHub Desktop.

Select an option

Save edunuke/4c8eb8b11065b3d78d0424371df79ed8 to your computer and use it in GitHub Desktop.
from keras.layers import Input, Dense, BatchNormalization
from keras.models import Model
from keras.callbacks import EarlyStopping
# set input layer
inputs = Input(shape=(X_train.shape[1],), name='input')
# normalized the batches
x = BatchNormalization(name='input_bn')(inputs)
# add the fully connected layers
x = Dense(X_train.shape[1], activation='relu', name='first')(x)
x = Dense(64, activation='relu',name='second')(x)
x = Dense(X_train.shape[1], activation='elu',name='last')(x)
# get the final result
predictions = Dense(1, activation='relu', name='ouput')(x)
# This creates a model that includes
# the Input layer and three Dense layers
model = Model(inputs=inputs, outputs=predictions)
model.compile(optimizer='adam',
loss='mape')
model.fit(X_train,
Y_train,
epochs = 100,
batch_size = 1000,
validation_data = (X_test,Y_test),
shuffle=True,
callbacks=[EarlyStopping(monitor='val_loss', patience=1,)])
#let's get the training and validation histories for plotting
val_loss = model.history.history['val_loss']
loss = model.history.history['loss']
print(model.summary())
# let's plot the performance curve
import matplotlib.pyplot as plt
plt.figure()
plt.plot(val_loss, label='val_loss')
plt.plot(loss, label = 'loss')
plt.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment