_SARIMAXAdapter

class _SARIMAXAdapter(order: Tuple[int, int, int] = (1, 0, 0), seasonal_order: Tuple[int, int, int, int] = (0, 0, 0, 0), trend: Optional[str] = None, measurement_error: bool = False, time_varying_regression: bool = False, mle_regression: bool = True, simple_differencing: bool = False, enforce_stationarity: bool = True, enforce_invertibility: bool = True, hamilton_representation: bool = False, concentrate_scale: bool = False, trend_offset: float = 1, use_exact_diffuse: bool = False, dates: Optional[List[datetime.datetime]] = None, freq: Optional[str] = None, missing: str = 'none', validate_specification: bool = True, **kwargs)[source]

Bases: etna.models.sarimax._SARIMAXBaseAdapter

Class for holding SARIMAX model.

Notes

We use SARIMAX [1] model from statsmodels package. Statsmodels package uses exog attribute for exogenous regressors which should be known in future, however we use exogenous for additional features what is not known in future, and regressors for features we do know in future.

Init SARIMAX model with given params.

Parameters
  • order (Tuple[int, int, int]) – The (p,d,q) order of the model for the number of AR parameters, differences, and MA parameters. d must be an integer indicating the integration order of the process, while p and q may either be an integers indicating the AR and MA orders (so that all lags up to those orders are included) or else iterables giving specific AR and / or MA lags to include. Default is an AR(1) model: (1,0,0).

  • seasonal_order (Tuple[int, int, int, int]) – The (P,D,Q,s) order of the seasonal component of the model for the AR parameters, differences, MA parameters, and periodicity. D must be an integer indicating the integration order of the process, while P and Q may either be an integers indicating the AR and MA orders (so that all lags up to those orders are included) or else iterables giving specific AR and / or MA lags to include. s is an integer giving the periodicity (number of periods in season), often it is 4 for quarterly data or 12 for monthly data. Default is no seasonal effect.

  • trend (Optional[str]) – Parameter controlling the deterministic trend polynomial \(A(t)\). Can be specified as a string where ‘c’ indicates a constant (i.e. a degree zero component of the trend polynomial), ‘t’ indicates a linear trend with time, and ‘ct’ is both. Can also be specified as an iterable defining the non-zero polynomial exponents to include, in increasing order. For example, [1,1,0,1] denotes \(a + bt + ct^3\). Default is to not include a trend component.

  • measurement_error (bool) – Whether or not to assume the endogenous observations endog were measured with error. Default is False.

  • time_varying_regression (bool) – Used when an explanatory variables, exog, are provided provided to select whether or not coefficients on the exogenous regressors are allowed to vary over time. Default is False.

  • mle_regression (bool) – Whether or not to use estimate the regression coefficients for the exogenous variables as part of maximum likelihood estimation or through the Kalman filter (i.e. recursive least squares). If time_varying_regression is True, this must be set to False. Default is True.

  • simple_differencing (bool) – Whether or not to use partially conditional maximum likelihood estimation. If True, differencing is performed prior to estimation, which discards the first \(s D + d\) initial rows but results in a smaller state-space formulation. See the Notes section for important details about interpreting results when this option is used. If False, the full SARIMAX model is put in state-space form so that all datapoints can be used in estimation. Default is False.

  • enforce_stationarity (bool) – Whether or not to transform the AR parameters to enforce stationarity in the autoregressive component of the model. Default is True.

  • enforce_invertibility (bool) – Whether or not to transform the MA parameters to enforce invertibility in the moving average component of the model. Default is True.

  • hamilton_representation (bool) – Whether or not to use the Hamilton representation of an ARMA process (if True) or the Harvey representation (if False). Default is False.

  • concentrate_scale (bool) – Whether or not to concentrate the scale (variance of the error term) out of the likelihood. This reduces the number of parameters estimated by maximum likelihood by one, but standard errors will then not be available for the scale parameter.

  • trend_offset (float) – The offset at which to start time trend values. Default is 1, so that if trend=’t’ the trend is equal to 1, 2, …, nobs. Typically is only set when the model created by extending a previous dataset.

  • use_exact_diffuse (bool) – Whether or not to use exact diffuse initialization for non-stationary states. Default is False (in which case approximate diffuse initialization is used).

  • dates (Optional[List[datetime.datetime]]) – If no index is given by endog or exog, an array-like object of datetime objects can be provided.

  • freq (Optional[str]) – If no index is given by endog or exog, the frequency of the time-series may be specified here as a Pandas offset or offset string.

  • missing (str) – Available options are ‘none’, ‘drop’, and ‘raise’. If ‘none’, no nan checking is done. If ‘drop’, any observations with nans are dropped. If ‘raise’, an error is raised. Default is ‘none’.

  • validate_specification (bool) – If True, validation of hyperparameters is performed.

  • **kwargs – Additional parameters for statsmodels.tsa.sarimax.SARIMAX.

Inherited-members

Methods

fit(df, regressors)

Fits a SARIMAX model.

forecast(df, prediction_interval, quantiles)

Compute autoregressive predictions from a SARIMAX model.

forecast_components(df)

Estimate forecast components.

get_model()

Get statsmodels.tsa.statespace.sarimax.SARIMAXResultsWrapper that is used inside etna class.

predict(df, prediction_interval, quantiles)

Compute predictions from a SARIMAX model and use true in-sample data as lags if possible.

predict_components(df)

Estimate prediction components.

fit(df: pandas.core.frame.DataFrame, regressors: List[str]) etna.models.sarimax._SARIMAXBaseAdapter

Fits a SARIMAX model.

Parameters
  • df (pandas.core.frame.DataFrame) – Features dataframe

  • regressors (List[str]) – List of the columns with regressors

Returns

Fitted model

Return type

etna.models.sarimax._SARIMAXBaseAdapter

forecast(df: pandas.core.frame.DataFrame, prediction_interval: bool, quantiles: Sequence[float]) pandas.core.frame.DataFrame

Compute autoregressive predictions from a SARIMAX model.

Parameters
  • df (pandas.core.frame.DataFrame) – Features dataframe

  • prediction_interval (bool) – If True returns prediction interval for forecast

  • quantiles (Sequence[float]) – Levels of prediction distribution

Returns

DataFrame with predictions

Return type

pandas.core.frame.DataFrame

forecast_components(df: pandas.core.frame.DataFrame) pandas.core.frame.DataFrame

Estimate forecast components.

Parameters

df (pandas.core.frame.DataFrame) – features dataframe

Returns

dataframe with forecast components

Return type

pandas.core.frame.DataFrame

get_model() statsmodels.tsa.statespace.sarimax.SARIMAXResultsWrapper

Get statsmodels.tsa.statespace.sarimax.SARIMAXResultsWrapper that is used inside etna class.

Returns

Internal model

Return type

statsmodels.tsa.statespace.sarimax.SARIMAXResultsWrapper

predict(df: pandas.core.frame.DataFrame, prediction_interval: bool, quantiles: Sequence[float]) pandas.core.frame.DataFrame

Compute predictions from a SARIMAX model and use true in-sample data as lags if possible.

Parameters
  • df (pandas.core.frame.DataFrame) – Features dataframe

  • prediction_interval (bool) – If True returns prediction interval for forecast

  • quantiles (Sequence[float]) – Levels of prediction distribution

Returns

DataFrame with predictions

Return type

pandas.core.frame.DataFrame

predict_components(df: pandas.core.frame.DataFrame) pandas.core.frame.DataFrame

Estimate prediction components.

Parameters

df (pandas.core.frame.DataFrame) – features dataframe

Returns

dataframe with prediction components

Return type

pandas.core.frame.DataFrame