title: How to detect the epoch where Keras earlyStopping occurred?
body: <p>I am training a neural network with Keras. I set <code>num_epochs</code> to a high number and let <code>EarlyStopping</code> terminate training.</p>
  
  <pre><code>model = Sequential()
  model.add(Dense(1, input_shape=(nFeatures,), activation='linear'))
  model.compile(optimizer='rmsprop', loss='mse', metrics=['mse', 'mae'])
  
  early_stopping_monitor = EarlyStopping(monitor='val_loss', patience=15, verbose=1, mode='auto')
  
  checkpointer = ModelCheckpoint(filepath = fname_saveWeights, verbose=1, save_best_only=True)
  
  seqModel = model.fit(X_train, y_train, batch_size=4, epochs=num_epochs, validation_data=(X_test, y_test), shuffle=True, callbacks=[early_stopping_monitor, checkpointer], verbose=2)
  </code></pre>
  
  <p>This works fine. However, I then attempt to plot the loss function:</p>
  
  <pre><code>val_loss   = seqModel.history['val_loss']
  xc         = range(num_epochs)
  plt.figure()
  plt.plot(xc, val_loss)
  plt.show()
  </code></pre>
  
  <p>I am attempting to plot the range of <code>num-epochs</code> (xc) but <code>EarlyStopping</code> ends much earlier, so I have an error in shapes.  </p>
  
  <p><strong>How can I detect at what epoch EarlyStopping ended to solve the mismatch?</strong></p>
  
  <p>Verbose setting prints the ending epoch to screen, but I cannot determine how to access the value to use in the plot.</p>