keras - noypeban/noypeban.github.io GitHub Wiki

model

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.layers import *

model = keras.Sequential([
    InputLayer(input_shape=(X.shape[1],)),
    BatchNormalization(),
    Dense(256, activation="relu"),
    Dense(64, activation="relu"),
    Dense(32, activation="relu"),
    Dropout(0.2),
    Dense(1, activation="sigmoid")
])
model.compile(loss='binary_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])

checkpoint = keras.callbacks.ModelCheckpoint('model.hdf5',monitor='val_loss',save_best_only=True,verbose=0)
history = model.fit(X_train, up_train, validation_data=(X_valid, up_valid), verbose=0, epochs=200, batch_size=128, callbacks=[checkpoint])
model.load_weights('model.hdf5')

history plot

import matplotlib.pyplot as plt
plt.plot(history.history['val_loss'])
plt.plot(history.history['val_acc'])

other