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.defaults
: Default models for anomaly detection and forecasting. These are good models for getting started.merlion.models.anomaly
: Anomaly detection modelsmerlion.models.anomaly.change_point
: Change point detection modelsmerlion.models.forecast
: Forecasting models, including those which support exogenous regressorsmerlion.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.spark
: APIs to integrate Merlion with PySpark for using distributed computing to run training and inference on multiple time series in parallel.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 seriesmerlion.utils
: Various utilities, including theTimeSeries
class, resampling functions, Bayesian conjugate priors, reconciliation for hierarchical time series, and more.
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.change_point package
- 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.ets module
- merlion.models.forecast.prophet module
- merlion.models.forecast.smoother module
- merlion.models.forecast.vector_ar module
- merlion.models.forecast.trees module
- merlion.models.forecast.lstm module
- merlion.models.ensemble package
- merlion.models.automl package
- merlion.models.anomaly package
- Submodules
- merlion.models.defaults module
- merlion.models.factory module
- merlion.models.base module
Config
NormalizingConfig
ModelBase
ModelBase.filename
ModelBase.config_class
ModelBase.train_data
ModelBase.reset()
ModelBase.base_model
ModelBase.require_even_sampling
ModelBase.require_univariate
ModelBase.auto_align
ModelBase.dim
ModelBase.transform
ModelBase.timedelta
ModelBase.last_train_time
ModelBase.train_pre_process()
ModelBase.transform_time_series()
ModelBase.train()
ModelBase.train_post_process()
ModelBase.save()
ModelBase.load()
ModelBase.to_bytes()
ModelBase.from_bytes()
MultipleTimeseriesModelMixin
- merlion.models.layers module
- Subpackages
- merlion.spark package
- merlion.transform package
- Submodules
- merlion.transform.base module
- merlion.transform.bound module
- merlion.transform.factory module
- merlion.transform.moving_average module
- merlion.transform.normalize module
- merlion.transform.resample module
- merlion.transform.sequence module
- merlion.transform.anomalize module
- merlion.post_process package
- merlion.evaluate package
- Submodules
- merlion.evaluate.base module
- merlion.evaluate.anomaly module
ScoreType
TSADScoreAccumulator
accumulate_tsad_score()
TSADMetric
TSADMetric.MeanTimeToDetect
TSADMetric.F1
TSADMetric.Precision
TSADMetric.Recall
TSADMetric.PointwiseF1
TSADMetric.PointwisePrecision
TSADMetric.PointwiseRecall
TSADMetric.PointAdjustedF1
TSADMetric.PointAdjustedPrecision
TSADMetric.PointAdjustedRecall
TSADMetric.NABScore
TSADMetric.NABScoreLowFN
TSADMetric.NABScoreLowFP
TSADMetric.F2
TSADMetric.F5
TSADEvaluatorConfig
TSADEvaluator
- merlion.evaluate.forecast module
- merlion.utils package
- Submodules
- merlion.utils.time_series module
UnivariateTimeSeries
UnivariateTimeSeries.__getitem__()
UnivariateTimeSeries.__iter__()
UnivariateTimeSeries.np_time_stamps
UnivariateTimeSeries.np_values
UnivariateTimeSeries.time_stamps
UnivariateTimeSeries.values
UnivariateTimeSeries.t0
UnivariateTimeSeries.tf
UnivariateTimeSeries.is_empty()
UnivariateTimeSeries.copy()
UnivariateTimeSeries.concat()
UnivariateTimeSeries.bisect()
UnivariateTimeSeries.window()
UnivariateTimeSeries.to_dict()
UnivariateTimeSeries.from_dict()
UnivariateTimeSeries.to_pd()
UnivariateTimeSeries.from_pd()
UnivariateTimeSeries.to_ts()
UnivariateTimeSeries.empty()
TimeSeries
TimeSeries.__getitem__()
TimeSeries.__iter__()
TimeSeries.names
TimeSeries.items()
TimeSeries.dim
TimeSeries.rename()
TimeSeries.is_aligned
TimeSeries.np_time_stamps
TimeSeries.time_stamps
TimeSeries.t0
TimeSeries.tf
TimeSeries.is_empty()
TimeSeries.squeeze()
TimeSeries.shape
TimeSeries.bisect()
TimeSeries.window()
TimeSeries.to_pd()
TimeSeries.to_csv()
TimeSeries.from_pd()
TimeSeries.from_ts_list()
TimeSeries.align()
assert_equal_timedeltas()
- merlion.utils.resample module
- merlion.utils.data_io module
- merlion.utils.hts module
- merlion.utils.ts_generator module
- merlion.utils.conj_priors module
- merlion.utils.istat module
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, 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 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)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, 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, 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. :param title: title of the plot. :param figsize: figure size in pixels :return: plotly figure.