Skip to content

Instantly share code, notes, and snippets.

@Karts27
Last active November 15, 2021 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Karts27/1b2db86de095e0ed4240293a3d5721ef to your computer and use it in GitHub Desktop.
Save Karts27/1b2db86de095e0ed4240293a3d5721ef to your computer and use it in GitHub Desktop.
es = EarlyStopping(monitor = 'val_accuracy', patience = 5)
# Run the model for a batch size of 5 for 100 epochs
history = model.fit(X_train,
y_train,
validation_data = (X_test, y_test),
batch_size = 5,
epochs = 100,
callbacks = es
)
# Function to plot "accuracy vs epoch" graphs and "loss vs epoch" graphs for training and validation data
def plot_metrics(model_name, metric = 'accuracy'):
if metric == 'loss':
plt.title("Loss Values")
plt.plot(model_name.history['loss'], label = 'train')
plt.plot(model_name.history['val_loss'], label = 'test')
plt.legend()
plt.show()
else:
plt.title("Accuracy Values")
plt.plot(model_name.history['accuracy'], label='train')
plt.plot(model_name.history['val_accuracy'], label='test')
plt.legend()
plt.show()
plot_metrics(history, 'accuracy')
plot_metrics(history, 'loss')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment