merlion: Time Series Intelligence
merlion
is a Python library for time series intelligence. We support the following key features,
each associated with its own sub-package:
merlion.models
: A library of models unified under a single shared interface, with specializations for anomaly detection and forecasting. More specifically, we havemerlion.models.anomaly
: Anomaly detection modelsmerlion.models.forecast
: Forecasting modelsmerlion.models.anomaly.forecast_based
: Forecasting models adapted for anomaly detection. Anomaly scores are based on the residual between the predicted and true value at each timestamp.merlion.models.ensemble
: Ensembles & automated model selection of models for both anomaly detection and forecasting.merlion.models.automl
: AutoML layers for various models
merlion.transform
: Data pre-processing layer which implements many standard data transformations used in time series analysis. Transforms are callable objects, and each model has its own configurablemodel.transform
which it uses to pre-process all input time series for both training and inference.merlion.post_process
: Post-processing rules to apply on the output of a model. Currently, these are specific to anomaly detection, and includemerlion.post_process.calibrate
: Rules to calibrate the anomaly scores returned by a model, to be interpretable as z-scores, i.e. as standard deviations of a standard normal random variable. Each anomaly detection model has amodel.calibrator
from this module, which can optionally be applied to ensure that the model’s anomaly scores are calibrated.merlion.post_process.threshold
: Rules to reduce the noisiness of an anomaly detection model’s outputs. Each anomaly detection model has amodel.threshold
from this module, which can optionally be applied to filter the model’s predicted sequence of anomaly scores.
merlion.evaluate
: Evaluation metrics & pipelines to simulate the live deployment of a time series model for any task.merlion.plot
: Automated visualization of model outputs for univariate time series
The key classes for input and output are merlion.utils.time_series.TimeSeries
and
merlion.utils.time_series.UnivariateTimeSeries
. Notably, these classes have transparent inter-operability
with pandas.DataFrame
and pandas.Series
, respectively. Check this tutorial
for some examples on how to use these classes, or the API docs linked above for a full list of features.
Subpackages
- merlion.models package
- Subpackages
- merlion.models.anomaly package
- Subpackages
- Submodules
- merlion.models.anomaly.base module
- merlion.models.anomaly.dbl module
- merlion.models.anomaly.windstats module
- merlion.models.anomaly.isolation_forest module
- merlion.models.anomaly.random_cut_forest module
- merlion.models.anomaly.spectral_residual module
- merlion.models.anomaly.stat_threshold module
- merlion.models.anomaly.zms module
- merlion.models.anomaly.autoencoder module
- merlion.models.anomaly.vae module
- merlion.models.anomaly.dagmm module
- merlion.models.anomaly.lstm_ed module
- merlion.models.anomaly.deep_point_anomaly_detector module
- merlion.models.anomaly.forecast_based package
- Submodules
- merlion.models.anomaly.forecast_based.base module
- merlion.models.anomaly.forecast_based.arima module
- merlion.models.anomaly.forecast_based.sarima module
- merlion.models.anomaly.forecast_based.ets module
- merlion.models.anomaly.forecast_based.prophet module
- merlion.models.anomaly.forecast_based.lstm module
- merlion.models.anomaly.forecast_based.mses module
- merlion.models.forecast package
- Submodules
- merlion.models.forecast.base module
- merlion.models.forecast.arima module
- merlion.models.forecast.sarima module
- merlion.models.forecast.prophet module
- merlion.models.forecast.smoother module
- merlion.models.forecast.vector_ar module
- merlion.models.forecast.baggingtrees module
- merlion.models.forecast.bo0stingtrees module
- merlion.models.forecast.lstm module
- merlion.models.ensemble package
- merlion.models.automl package
- merlion.models.anomaly package
- Submodules
- merlion.models.base module
- merlion.models.factory module
- merlion.models.defaults module
- Subpackages
- merlion.transform package
- merlion.post_process package
- merlion.evaluate package
- merlion.utils package
Submodules
merlion.plot module
Module for visualizing model predictions.
- merlion.plot.plot_anoms(ax, anomaly_labels)
Plots anomalies as pink windows on the matplotlib
Axes
objectax
.
- merlion.plot.plot_anoms_plotly(fig, anomaly_labels)
Plots anomalies as pink windows on the plotly
Figure
objectfig
.
- 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)
Bases:
object
Class for visualizing predictions of univariate anomaly detection & forecasting models.
- Parameters
y (
Optional
[UnivariateTimeSeries
]) – the true value of the time seriesanom (
Optional
[UnivariateTimeSeries
]) – anomaly scores returned by a modelyhat (
Optional
[UnivariateTimeSeries
]) – forecast returned by a modelyhat_lb (
Optional
[UnivariateTimeSeries
]) – lower bound onyhat
(if model supports uncertainty estimation)yhat_ub (
Optional
[UnivariateTimeSeries
]) – upper bound onyhat
(if model supports uncertainty estimation)y_prev (
Optional
[UnivariateTimeSeries
]) – portion of time series precedingy
yhat_prev (
Optional
[UnivariateTimeSeries
]) – model’s forecast ofy_prev
yhat_prev_lb (
Optional
[UnivariateTimeSeries
]) – lower bound onyhat_prev
(if model supports uncertainty estimation)yhat_prev_ub (
Optional
[UnivariateTimeSeries
]) – upper bound onyhat_prev
(if model supports uncertainty estimation)
- 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, specificallyy_hat
andanom
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, specificallyy_hat
andanom
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)
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. :param title: title of the plot. :param figsize: figure size in pixels :return: plotly figure.