Monitoring utils

neptunecontrib.monitoring.utils.axes2fig(axes, fig=None)[source]

Converts ndarray of matplotlib object to matplotlib figure.

Scikit-optimize plotting functions return ndarray of axes. This can be tricky to work with so you can use this function to convert it to the standard figure format.

Parameters:
  • axes (numpy.ndarray) – Array of matplotlib axes objects.
  • fig ('matplotlib.figure.Figure') – Matplotlib figure on which you may want to plot your axes. Default None.
Returns:

Matplotlib figure with axes objects as subplots.

Return type:

‘matplotlib.figure.Figure’

Examples

Assuming you have a scipy.optimize.OptimizeResult object you want to plot:

from skopt.plots import plot_evaluations
eval_plot = plot_evaluations(result, bins=20)
>>> type(eval_plot)
    numpy.ndarray

from neptunecontrib.viz.utils import axes2fig
fig = axes2fig(eval_plot)
>>> fig
    matplotlib.figure.Figure
neptunecontrib.monitoring.utils.pickle_and_send_artifact(obj, filename, experiment=None)[source]

Logs picklable object to Neptune.

Pickles and logs your object to Neptune under specified filename.

Parameters:
  • obj – Picklable object.
  • filename (str) – filename under which object will be saved.
  • experiment (neptune.experiments.Experiment) – Neptune experiment. Default is None.

Examples

Initialize Neptune:

import neptune
neptune.init('USER_NAME/PROJECT_NAME')

Create RandomForest object and log to Neptune:

from sklearn.ensemble import RandomForestClassifier
from neptunecontrib.monitoring.utils import pickle_and_send_artifact

with neptune.create_experiment():
    rf = RandomForestClassifier()
    pickle_and_send_artifact(rf, 'rf')
neptunecontrib.monitoring.utils.send_figure(fig, channel_name='figures', experiment=None)[source]

Logs matplotlib figure to Neptune.

Logs any figure from matplotlib to specified image channel. By default it logs to ‘figures’ and you can log multiple images to the same channel.

Parameters:
  • channel_name (str) – name of the neptune channel. Default is ‘figures’.
  • experiment (neptune.experiments.Experiment) – Neptune experiment. Default is None.
  • fig (matplotlib.figure) – Matplotlib figure object

Examples

Initialize Neptune:

import neptune
neptune.init('USER_NAME/PROJECT_NAME')

Create random data::

import numpy as np
table = np.random.random((10,10))

Plot and log to Neptune:

import matplotlib.pyplot as plt
import seaborn as sns
from neptunecontrib.monitoring.utils import send_figure

with neptune.create_experiment():
    fig, ax = plt.subplots()
    sns.heatmap(table,ax=ax)
    send_figure(fig)