merlion.plot package

Module for visualizing model predictions.

merlion.plot.plot_anoms(ax, anomaly_labels)

Plots anomalies as pink windows on the matplotlib Axes object ax.

merlion.plot.plot_anoms_plotly(fig, anomaly_labels)

Plots anomalies as pink windows on the plotly Figure object fig.

class merlion.plot.Figure(y=None, anom=None, yhat=None, yhat_lb=None, yhat_ub=None, y_prev=None, yhat_prev=None, yhat_prev_lb=None, yhat_prev_ub=None, yhat_color=None)

Bases: object

Class for visualizing predictions of univariate anomaly detection & forecasting models.

Parameters
  • y (Optional[UnivariateTimeSeries]) – the true value of the time series

  • anom (Optional[UnivariateTimeSeries]) – anomaly scores returned by a model

  • yhat (Optional[UnivariateTimeSeries]) – forecast returned by a model

  • yhat_lb (Optional[UnivariateTimeSeries]) – lower bound on yhat (if model supports uncertainty estimation)

  • yhat_ub (Optional[UnivariateTimeSeries]) – upper bound on yhat (if model supports uncertainty estimation)

  • y_prev (Optional[UnivariateTimeSeries]) – portion of time series preceding y

  • yhat_prev (Optional[UnivariateTimeSeries]) – model’s forecast of y_prev

  • yhat_prev_lb (Optional[UnivariateTimeSeries]) – lower bound on yhat_prev (if model supports uncertainty estimation)

  • yhat_prev_ub (Optional[UnivariateTimeSeries]) – upper bound on yhat_prev (if model supports uncertainty estimation)

  • yhat_color (Optional[str]) – the color in which to plot the forecast

property t0
Returns

First time being plotted.

property tf
Returns

Final time being plotted.

property t_split
Returns

Time splitting train from test.

get_y()

Get all y’s (actual values)

get_yhat()

Get all yhat’s (predicted values).

get_yhat_iqr()

Get IQR of predicted values.

plot(title=None, metric_name=None, figsize=(1000, 600), ax=None, label_alias=None)

Plots the figure in matplotlib.

Parameters
  • title – title of the plot.

  • metric_name – name of the metric (y axis)

  • figsize – figure size in pixels

  • ax – matplotlib axes to add the figure to.

  • label_alias (Optional[Dict[str, str]]) – dict which maps entities in the figure, specifically y_hat and anom to their label names.

Returns

(fig, ax): matplotlib figure & matplotlib axes

plot_plotly(title=None, metric_name=None, figsize=(1000, 600), label_alias=None)

Plots the figure in plotly.

Parameters
  • title – title of the plot.

  • metric_name – name of the metric (y axis)

  • figsize – figure size in pixels

  • label_alias (Optional[Dict[str, str]]) – dict which maps entities in the figure, specifically y_hat and anom to their label names.

Returns

plotly figure.

class merlion.plot.MTSFigure(y=None, anom=None, yhat=None, yhat_lb=None, yhat_ub=None, y_prev=None, yhat_prev=None, yhat_prev_lb=None, yhat_prev_ub=None, yhat_color=None)

Bases: object

property t0
property tf
property t_split
get_y()

Get all y’s (actual values)

get_yhat()

Get all yhat’s (predicted values).

get_yhat_iqr()

Get IQR of predicted values.

plot_plotly(title=None, figsize=None)

Plots the figure in plotly. :type title: :param title: title of the plot. :type figsize: :param figsize: figure size in pixels :return: plotly figure.