plot-keras-history

A simple python package to print a keras NN training history.

https://github.com/lucacappelletti94/plot_keras_history

Science Score: 57.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.1%) to scientific vocabulary
Last synced: 7 months ago · JSON representation ·

Repository

A simple python package to print a keras NN training history.

Basic Info
  • Host: GitHub
  • Owner: LucaCappelletti94
  • License: mit
  • Language: Python
  • Default Branch: master
  • Size: 12 MB
Statistics
  • Stars: 18
  • Watchers: 1
  • Forks: 4
  • Open Issues: 0
  • Releases: 3
Created almost 7 years ago · Last pushed over 1 year ago
Metadata Files
Readme Funding License Citation

README.md

Plot Keras History

PyPI License Downloads Github Actions

A Python package to print a Keras model training history.

How do I install this package?

As usual, just download it using pip:

bash 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

```python from keras.models import Sequential from keras.layers import Dense import matplotlib.pyplot as plt import numpy as np from plotkerashistory import showhistory, plothistory

model = Sequential([ Dense(1, activation="sigmoid") ]) model.compile( optimizer="nadam", loss="binarycrossentropy" ) X = np.random.uniform(size=(100, 100)) y = np.random.randint(2, size=(100)) history = model.fit( X[:50], y[:50], validationdata=(X[50:], y[50:]), epochs=10, verbose=False ) showhistory(history) plothistory(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:

```python from keras.models import Sequential from keras.layers import Dense import matplotlib.pyplot as plt import numpy as np from plotkerashistory import plot_history

model = Sequential([ Dense(1, activation="sigmoid") ]) model.compile( optimizer="nadam", loss="binarycrossentropy" ) X = np.random.uniform(size=(100, 100)) y = np.random.randint(2, size=(100)) history = model.fit( X[:50], y[:50], validationdata=(X[50:], y[50:]), epochs=10, verbose=False ) plothistory(history, path="singleton", singlegraphs=True) plt.close() ```

Plotting multiple histories

Suppose you are training your model on multiple holdouts and want to plot all of them, plus an average. Fortunately, we've got you covered!

Multiple Histories

```python from keras.models import Sequential from keras.layers import Dense import matplotlib.pyplot as plt import numpy as np from plotkerashistory import plot_history

histories = [] for holdout in range(10): model = Sequential([ Dense(1, activation="sigmoid") ]) model.compile( optimizer="nadam", loss="binarycrossentropy" ) X = np.random.uniform(size=(100, 100)) y = np.random.randint(2, size=(100)) history = model.fit( X[:50], y[:50], validationdata=(X[50:], y[50:]), epochs=10, verbose=False ) histories.append(history)

plothistory( histories, showstandarddeviation=False, showaverage=True ) plt.close() ```

Reducing the history noise with Savgol Filters

In some cases, it is necessary to see the progress of the history while interpolating results to reduce noise. A parameter is available to automatically apply a Savgol filter:

Interpolated

```python from keras.models import Sequential from keras.layers import Dense import matplotlib.pyplot as plt import numpy as np from plotkerashistory import plot_history

model = Sequential([ Dense(1, activation="sigmoid") ]) model.compile( optimizer="nadam", loss="binarycrossentropy" ) X = np.random.uniform(size=(100, 100)) y = np.random.randint(2, size=(100)) history = model.fit( X[:50], y[:50], validationdata=(X[50:], y[50:]), epochs=10, verbose=False ) plot_history(history, path="interpolated.png", interpolate=True) plt.close() ```

Automatic aliases

Metrics such as "lr" (Learning Rate) or "acc" (Accuracy) are automatically renamed to more descriptive labels.

Automatic normalization

The library normalizes the ranges of metrics known to be in [-1, 1] or [0, 1] to avoid visual biases.

All the available options

```python from keras.models import Sequential from keras.layers import Dense import matplotlib.pyplot as plt import numpy as np from plotkerashistory import plot_history

model = Sequential([ Dense(1, activation="sigmoid") ]) model.compile( optimizer="nadam", loss="binarycrossentropy" ) X = np.random.uniform(size=(100, 100)) y = np.random.randint(2, size=(100)) history = model.fit( X[:50], y[:50], validationdata=(X[50:], y[50:]), epochs=10, verbose=False ) plothistory( history, style="-", # Line style. interpolate=True, # Whether to interpolate graph datapoints. side=5, # Graph size. graphsperrow=4, # Number of graphs per row. customizationcallback=None, # Callback for customizing graphs. path="interpolated.png", # Save path for the resulting image or images (for singlegraphs). singlegraphs=False # Whether to save as single or multiple graphs. ) plt.close() ```

Chaining histories

If you stop and restart a model's training, it may break the history into two objects. Use chain_histories to merge them:

```python from keras.models import Sequential from keras.layers import Dense import numpy as np from plotkerashistory import chain_histories

model = Sequential([ Dense(1, activation="sigmoid") ]) model.compile( optimizer="nadam", loss="binarycrossentropy" ) X = np.random.uniform(size=(100, 100)) y = np.random.randint(2, size=(100)) model = Sequential([ Dense(1, activation="sigmoid") ]) model.compile( optimizer="nadam", loss="binarycrossentropy" ) X = np.random.uniform(size=(100, 100)) y = np.random.randint(2, size=(100)) history1 = model.fit( X[:50], y[:50], validationdata=(X[50:], y[50:]), epochs=10, verbose=False ) history2 = model.fit( X[:50], y[:50], validationdata=(X[50:], y[50:]), epochs=10, verbose=False ) 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:

bibtex @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} }

Owner

  • Name: Luca Cappelletti
  • Login: LucaCappelletti94
  • Kind: user
  • Location: Milano, Italy
  • Company: University of Fribourg

I am but an egg 🥚 - "Stranger in a Strange Land"

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
  - family-names: Cappelletti
    given-names: Luca
    orcid: https://orcid.org/my-orcid?orcid=0000-0002-1269-2038
title: "Plot Keras History"
version: 1.1.36
doi: 10.5072/zenodo.1054923
date-released: 2022-04-25

GitHub Events

Total
  • Create event: 1
  • Release event: 1
  • Issues event: 1
  • Watch event: 1
  • Issue comment event: 3
  • Push event: 8
Last Year
  • Create event: 1
  • Release event: 1
  • Issues event: 1
  • Watch event: 1
  • Issue comment event: 3
  • Push event: 8

Committers

Last synced: 10 months ago

All Time
  • Total Commits: 124
  • Total Committers: 1
  • Avg Commits per committer: 124.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 9
  • Committers: 1
  • Avg Commits per committer: 9.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
LucaCappelletti94 c****4@g****m 124

Issues and Pull Requests

Last synced: 8 months ago

All Time
  • Total issues: 4
  • Total pull requests: 0
  • Average time to close issues: 4 days
  • Average time to close pull requests: N/A
  • Total issue authors: 4
  • Total pull request authors: 0
  • Average comments per issue: 2.25
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: about 8 hours
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 3.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • clstaudt (1)
  • ryukinix (1)
  • MarvelFyy (1)
  • LucaCappelletti94 (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 270 last-month
  • Total dependent packages: 2
  • Total dependent repositories: 5
  • Total versions: 41
  • Total maintainers: 1
pypi.org: plot-keras-history

A simple python package to print a keras NN training history.

  • Versions: 41
  • Dependent Packages: 2
  • Dependent Repositories: 5
  • Downloads: 270 Last month
Rankings
Dependent packages count: 4.7%
Dependent repos count: 6.7%
Downloads: 8.3%
Average: 9.9%
Stargazers count: 14.5%
Forks count: 15.4%
Maintainers (1)
Last synced: 8 months ago

Dependencies

setup.py pypi
  • matplotlib *
  • pandas *
  • sanitize_ml_labels >=1.0.48
  • scipy *
  • support_developer >=1.0.2
.github/workflows/mypy.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
.github/workflows/python.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite