plot_history
keras.plot_history(history, *, metrics=None)Draw the training curves of a Keras model.
One chart per metric, stacked top to bottom, with the epoch along the x axis and two lines, named training and validation: the metric on the training data, and on the validation data when model.fit was given some. A metric with no validation values, such as the learning rate, is one line named for the metric. The loss comes first.
As in Keras, a metric whose name starts with val_ is read as the validation curve of the metric named without it.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| history | keras.callbacks.History or dict |
What model.fit returns, or its .history dictionary, which maps each metric, such as "loss" or "val_accuracy", to its value at each epoch. |
required |
| metrics | iterable of str | Only these metrics, in this order, named without the val_ prefix, such as ["loss", "accuracy"]. A metric not in history is warned about. |
None |
Returns
| Name | Type | Description |
|---|---|---|
matplotlib.figure.Figure |
The charts, ready for :func:maidr.show, :func:maidr.render or :func:maidr.save_html. The figure is not managed by pyplot, so plt.show() does not show it. |
Raises
| Name | Type | Description |
|---|---|---|
| TypeError | If history is neither a History nor a dictionary. |
|
| ValueError | If history holds no metric that can be drawn. |
Notes
Epochs are counted from 1, as Keras counts them when it trains. A value that is not finite, such as a loss that became NaN, is a gap in the line. A metric whose value is not a single number at each epoch, such as a per-class score, is left out with a warning.
With validation_freq above 1, Keras records the validation values on fewer epochs than the training ones without saying which, so plot_history leaves them out with a warning. :class:MaidrCallback records the epoch of every value and draws them.
Examples
>>> import maidr
>>> from maidr.keras import plot_history
>>> history = {"loss": [0.9, 0.6, 0.5], "val_loss": [1.0, 0.7, 0.65]}
>>> maidr.save_html(plot_history(history), "training.html")