merlion.models.automl package
Contains all AutoML layers.
Base class/mixin for AutoML hyperparameter search. 

Automatic seasonality detection. 


Automatic seasonality detection for ETS. 

Automatic (multi)seasonality detection for Facebook's Prophet. 
Automatic hyperparameter selection for SARIMA. 
Submodules
merlion.models.automl.base module
Base class/mixin for AutoML hyperparameter search.
 class merlion.models.automl.base.AutoMLMixIn(config=None, model=None, **kwargs)
Bases:
LayeredModel
Base Interface for Implemented AutoML Layers
This abstract class contains all of the methods that Layers should implement. Ideally, these would be generated by an existing mixin.
 config_class
alias of
LayeredModelConfig
 train(train_data, **kwargs)
Trains the model on the specified time series, optionally with some additional implementationspecific config options
train_config
. Parameters
train_data (
TimeSeries
) – aTimeSeries
to use as a training settrain_config – additional configurations (if needed)
 abstract generate_theta(train_data)
 Parameters
train_data (
TimeSeries
) – Training data to use for generation of hyperparameters \(\theta\)
Returns an iterator of hyperparameter candidates for consideration with th underlying model.
 Return type
Iterator
 abstract evaluate_theta(thetas, train_data, train_config=None)
 Parameters
thetas (
Iterator
) – Iterator of the hyperparameter candidatestrain_data (
TimeSeries
) – Training datatrain_config – Training configuration
Return the optimal hyperparameter, as well as optionally a model and result of the training procedure.
 Return type
Tuple
[Any
,Optional
[ForecasterBase
],Optional
[Tuple
[TimeSeries
,Optional
[TimeSeries
]]]]
 abstract set_theta(model, theta, train_data=None)
 Parameters
model – Underlying base model to which the new theta is applied
theta – Hyperparameter to apply
train_data (
Optional
[TimeSeries
]) – Training data (Optional)
Sets the hyperparameter to the provided
model
. This is used to apply the \(\theta\) to the model, since this behavior is custom to every model. Oftentimes in internal implementations,model
is the optimal model.
merlion.models.automl.autosarima module
Automatic hyperparameter selection for SARIMA.
 class merlion.models.automl.autosarima.AutoSarimaConfig(model=None, auto_seasonality=True, periodicity_strategy=PeriodicityStrategy.ACF, auto_pqPQ=True, auto_d=True, auto_D=True, maxiter=None, max_k=100, max_dur=3600, approximation=None, approx_iter=None, pval=0.05, model_kwargs=None, transform=None, **kwargs)
Bases:
SeasonalityConfig
Configuration class for
AutoSarima
. Acts as a wrapper around aSarima
model, which automatically detects the seasonality, (seasonal) differencing order, and (seasonal) AR/MA orders. If a nonnumeric value is specified for any of the relevant parameters in the order or seasonal order, we assume that the user wishes to detect that parameter automatically.Note
The automatic selection of AR, MA, seasonal AR, and seasonal MA parameters is implemented in a coupled way. The user must specify all of these parameters explicitly to avoid automatic selection.
 Parameters
model (
Union
[Sarima
,dict
,None
]) – The model being wrapped, or a dict representing it.auto_seasonality (
bool
) – Whether to automatically detect the seasonality.periodicity_strategy (
PeriodicityStrategy
) – Strategy to choose the seasonality if multiple candidates are detected.auto_pqPQ (
bool
) – Whether to automatically choose AR/MA ordersp, q
and seasonal AR/MA ordersP, Q
.auto_d (
bool
) – Whether to automatically choose the difference orderd
.auto_D (
bool
) – Whether to automatically choose the seasonal difference orderD
.maxiter (
Optional
[int
]) – The maximum number of iterations to performmax_k (
int
) – Maximum number of models considered in the stepwise searchmax_dur (
float
) – Maximum training time considered in the stepwise searchapproximation (
Optional
[bool
]) – Whether to useapprox_iter
iterations (instead ofmaxiter
) to speed up computation. IfNone
, we use approximation mode when the training data is too long (>150), or when the length off the period is too high (periodicity > 12
).approx_iter (
Optional
[int
]) – The number of iterations to perform in approximation modepval – pvalue for deciding whether a detected seasonality is statistically significant.
model_kwargs – Keyword arguments used specifically to initialize the underlying model. Only used if
model
is a dict. Will override keys in themodel
dict if specified.transform – Transformation to preprocess input time series.
kwargs – Any other keyword arguments (e.g. for initializing a base class). If
model
is a dict, we will also try to pass these arguments when creating the actual underlying model. However, they will not override arguments in either themodel
dict ormodel_kwargs
dict.
 property order
 property seasonal_order
 class merlion.models.automl.autosarima.AutoSarima(config=None, model=None, **kwargs)
Bases:
SeasonalityLayer
 config_class
alias of
AutoSarimaConfig
 require_even_sampling = True
 require_univariate = True
 generate_theta(train_data)
generate [action, theta]. action is an indicator for stepwise seach (stepwsie) of p, q, P, Q, trend parameters or use a predefined parameter combination (pqPQ) theta is a list of parameter combination [order, seasonal_order, trend]
 Return type
Iterator
 evaluate_theta(thetas, train_data, train_config=None)
 Parameters
thetas (
Iterator
) – Iterator of the hyperparameter candidatestrain_data (
TimeSeries
) – Training datatrain_config – Training configuration
Return the optimal hyperparameter, as well as optionally a model and result of the training procedure.
 Return type
Tuple
[Any
,Optional
[Sarima
],Optional
[Tuple
[TimeSeries
,Optional
[TimeSeries
]]]]
 set_theta(model, theta, train_data=None)
 Parameters
model – Underlying base model to which the new theta is applied
theta – Hyperparameter to apply
train_data (
Optional
[TimeSeries
]) – Training data (Optional)
Sets the hyperparameter to the provided
model
. This is used to apply the \(\theta\) to the model, since this behavior is custom to every model. Oftentimes in internal implementations,model
is the optimal model.
merlion.models.automl.seasonality module
Automatic seasonality detection.
 class merlion.models.automl.seasonality.PeriodicityStrategy(value)
Bases:
Enum
Strategy to choose the seasonality if multiple candidates are detected.
 ACF = 1
Select the seasonality value with the highest autocorrelation.
 Min = 2
Select the minimum seasonality.
 Max = 3
Select the maximum seasonality.
 All = 4
Use all seasonalities. Only valid for models which support multiple seasonalities.
 class merlion.models.automl.seasonality.SeasonalityModel
Bases:
object
Class provides simple implementation to set the seasonality in a model. Extend this class to implement custom behavior for seasonality processing.
 abstract set_seasonality(theta, train_data)
Implement this method to do any modelspecific adjustments on the seasonality that was provided by
SeasonalityLayer
. Parameters
theta – Seasonality processed by
SeasonalityLayer
.train_data (
UnivariateTimeSeries
) – Training data (or numpy array representing the target univariate) for any modelspecific adjustments you might want to make.
 class merlion.models.automl.seasonality.SeasonalityConfig(model, periodicity_strategy=PeriodicityStrategy.ACF, pval=0.05, model_kwargs=None, transform=None, **kwargs)
Bases:
LayeredModelConfig
Config object for an automatic seasonality detection layer.
 Parameters
model – The model being wrapped, or a dict representing it.
periodicity_strategy – Strategy to choose the seasonality if multiple candidates are detected.
pval (
float
) – pvalue for deciding whether a detected seasonality is statistically significant.model_kwargs – Keyword arguments used specifically to initialize the underlying model. Only used if
model
is a dict. Will override keys in themodel
dict if specified.transform – Transformation to preprocess input time series.
kwargs – Any other keyword arguments (e.g. for initializing a base class). If
model
is a dict, we will also try to pass these arguments when creating the actual underlying model. However, they will not override arguments in either themodel
dict ormodel_kwargs
dict.
 property multi_seasonality
 Returns
Whether the model supports multiple seasonalities.
False
unless explicitly overridden.
 property periodicity_strategy: PeriodicityStrategy
 Return type
 Returns
Strategy to choose the seasonality if multiple candidates are detected.
 to_dict(_skipped_keys=None)
 Returns
dict with keyword arguments used to initialize the config class.
 class merlion.models.automl.seasonality.SeasonalityLayer(config=None, model=None, **kwargs)
Bases:
AutoMLMixIn
Seasonality Layer that uses AutoSARIMAlike methods to determine seasonality of your data. Can be used directly on any model that implements
SeasonalityModel
class. config_class
alias of
SeasonalityConfig
 require_even_sampling = False
 property require_univariate
bool(x) > bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
 property multi_seasonality
 Returns
Whether the model supports multiple seasonalities.
 property periodicity_strategy
 Returns
Strategy to choose the seasonality if multiple candidates are detected.
 property pval
 Returns
pvalue for deciding whether a detected seasonality is statistically significant.
 set_theta(model, theta, train_data=None)
 Parameters
model – Underlying base model to which the new theta is applied
theta – Hyperparameter to apply
train_data (
Optional
[TimeSeries
]) – Training data (Optional)
Sets the hyperparameter to the provided
model
. This is used to apply the \(\theta\) to the model, since this behavior is custom to every model. Oftentimes in internal implementations,model
is the optimal model.
 evaluate_theta(thetas, train_data, train_config=None)
 Parameters
thetas (
Iterator
) – Iterator of the hyperparameter candidatestrain_data (
TimeSeries
) – Training datatrain_config – Training configuration
Return the optimal hyperparameter, as well as optionally a model and result of the training procedure.
 Return type
Tuple
[Any
,Optional
[ModelBase
],Optional
[Tuple
[TimeSeries
,Optional
[TimeSeries
]]]]
 generate_theta(train_data)
 Parameters
train_data (
TimeSeries
) – Training data to use for generation of hyperparameters \(\theta\)
Returns an iterator of hyperparameter candidates for consideration with th underlying model.
 Return type
Iterator