Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lucacappelletti94/plot_keras_history
A simple python package to print a keras NN training history.
https://github.com/lucacappelletti94/plot_keras_history
Last synced: 14 days ago
JSON representation
A simple python package to print a keras NN training history.
- Host: GitHub
- URL: https://github.com/lucacappelletti94/plot_keras_history
- Owner: LucaCappelletti94
- License: mit
- Created: 2019-05-05T16:50:09.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-11-19T12:01:19.000Z (almost 2 years ago)
- Last Synced: 2024-10-04T13:39:40.524Z (about 1 month ago)
- Language: Python
- Size: 11.5 MB
- Stars: 17
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Funding: .github/FUNDING.yml
- License: LICENSE
- Citation: CITATION.cff
Awesome Lists containing this project
README
Plot Keras History
=========================================================================================
|pip| |downloads|A python package to print a `Keras model training history `_
How do I install this package?
----------------------------------------------
As usual, just download it using pip:.. code:: shell
pip install plot_keras_history
Usage
------------------------------------------------
Let's say you have a model generated by the function my_keras_model:Plotting a training history
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the following example we will see how to plot and either show or save the training history:|standard|
.. code:: python
from plot_keras_history import show_history, plot_history
import matplotlib.pyplot as pltmodel = my_keras_model()
history = model.fit(...)
show_history(history)
plot_history(history, path="standard.png")
plt.close()Plotting into separate graphs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
By default, the graphs are all in one big image, but for various reasons you might need them one by one:.. code:: python
from plot_keras_history import plot_history
import matplotlib.pyplot as pltmodel = my_keras_model()
history = model.fit(...)
plot_history(history, path="singleton", single_graphs=True)
plt.close()Plotting multiple histories
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Let's suppose you are training your model on multiple holdouts and you would like to plot all of them,
plus an average. Fortunately, we got you covered!|multiple_histories|
.. code:: python
from plot_keras_history import plot_history
import matplotlib.pyplot as plthistories = []
for holdout in range(10):
model = my_keras_model()
histories.append(model.fit(...))
plot_history(
histories,
show_standard_deviation=False,
show_average=True
)
plt.close()Reducing the history noise with Savgol Filters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In some occasion it is necessary to be able to see the progress of the history to interpolate the results to remove a bit of noise. A parameter is offered to automatically apply a Savgol filter:|interpolated|
.. code:: python
from plot_keras_history import plot_history
import matplotlib.pyplot as pltmodel = my_keras_model()
history = model.fit(...)
plot_history(history, path="interpolated.png", interpolate=True)
plt.close()Automatic aliases
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A number of metrics are automatically converted from the default ones to more talking ones, for example "lr" becomes "Learning Rate", or "acc" becomes "Accuracy".Automatic normalization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The library automatically normalizes the ranges of metrics that are known to be either in [-1, 1] or [0, 1] ranges in order
to avoid visual biases.All the available options
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.. code:: python
def plot_history(
history, # Either the history object or a pandas DataFrame. When using a dataframe, the index name is used as abscissae label.
style:str="-", # The style of the lines.
interpolate: bool = False, # Wethever to interpolate or not the graphs datapoints.
side: float = 5, # Dimension of the graphs side.
graphs_per_row: int = 4, # Number of graphs for each row.
customization_callback: Callable = None, # Callback for customizing the graphs.
path: str = None, # Path where to store the resulting image or images (in the case of single_graphs)
single_graphs: bool = False # Wethever to save the graphs as single of multiples.
)Chaining histories
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It's common to stop and restart a model's training, and this would break the history object into two: for this reason the method `chain_histories `_ is available:.. code:: python
from plot_keras_history import chain_histories
model = my_keras_model()
history1 = model.fit(...)
history2 = model.fit(...)
history = chain_histories(history1, history2)Extras
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Numerous additional metrics are available in `extra_keras_metrics `_Cite this software
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you need a bib file to cite this work, here you have it:.. code:: bib
@software{Cappelletti_Plot_Keras_History_2022,
author = {Cappelletti, Luca},
doi = {10.5072/zenodo.1054923},
month = {4},
title = {{Plot Keras History}},
version = {1.1.36},
year = {2022}
}.. |pip| image:: https://badge.fury.io/py/plot-keras-history.svg
:target: https://badge.fury.io/py/plot-keras-history
:alt: Pypi project.. |downloads| image:: https://pepy.tech/badge/plot-keras-history
:target: https://pepy.tech/badge/plot-keras-history
:alt: Pypi total project downloads.. |standard| image:: https://github.com/LucaCappelletti94/plot_keras_history/blob/master/plots/normal.png?raw=true
.. |interpolated| image:: https://github.com/LucaCappelletti94/plot_keras_history/blob/master/plots/interpolated.png?raw=true
.. |multiple_histories| image:: https://github.com/LucaCappelletti94/plot_keras_history/blob/master/plots/multiple_histories.png?raw=true