Skip to main content

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

Project description

Pypi project Pypi total project downloads

A python package to print a Keras model training history

How do I install this package?

As usual, just download it using pip:

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

from plot_keras_history import show_history, plot_history
import matplotlib.pyplot as plt

model = 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:

from plot_keras_history import plot_history
import matplotlib.pyplot as plt

model = 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

from plot_keras_history import plot_history
import matplotlib.pyplot as plt

histories = []
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

from plot_keras_history import plot_history
import matplotlib.pyplot as plt

model = 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

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:

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plot_keras_history-1.1.35.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file plot_keras_history-1.1.35.tar.gz.

File metadata

  • Download URL: plot_keras_history-1.1.35.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.9

File hashes

Hashes for plot_keras_history-1.1.35.tar.gz
Algorithm Hash digest
SHA256 2e62af7b420466f39ae2298b161866cf3103e8c54c35e440bc76d62590437bfc
MD5 dd678da57dfd2c954a1b7c67721c3ce3
BLAKE2b-256 7d62aa90f70ab72be1ede7c348220a318d91f7f4dc8c5d41d96b3335fe570299

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page