Skip to content

Instantly share code, notes, and snippets.

@MaxHalford
Created May 24, 2018 15:20
Show Gist options
  • Save MaxHalford/e661602ae9e60fd04df94d6c15a303a3 to your computer and use it in GitHub Desktop.
Save MaxHalford/e661602ae9e60fd04df94d6c15a303a3 to your computer and use it in GitHub Desktop.
Keras eval callback
import keras
class EvalCallback(keras.callbacks.Callback):
def __init__(self, X_val, y_val, metric):
super().__init__()
self.X_val = X_val
self.y_val = y_val
self.metric = metric
def on_epoch_end(self, epoch, logs={}):
y_pred = self.model.predict(self.X_val, verbose=0)
score = self.metric(self.y_val, y_pred)
print('\nEpoch {} score: {:.6f}\n'.format(epoch+1, score))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment