SARIMAX
(S)ARIMA(X) forecaster, from statsmodels, tsa.statespace module.
Quickstart
from sktime.forecasting.sarimax import SARIMAX
estimator = SARIMAX(order=(1, 0, 0), seasonal_order=(0, 0, 0, 0), trend='c', measurement_error=False, time_varying_regression=False, mle_regression=True, simple_differencing=False, enforce_stationarity=True, enforce_invertibility=True, hamilton_representation=False, concentrate_scale=False, trend_offset=1, use_exact_diffuse=False, dates=None, freq=None, missing='none', validate_specification=True, disp=False, random_state=None, start_params=None, transformed=True, includes_fixed=False, cov_type=None, cov_kwds=None, method='lbfgs', maxiter=50, full_output=1, callback=None, return_params=False, optim_score=None, optim_complex_step=None, optim_hessian=None, low_memory=False)Parameters(29)
- orderiterable or iterable of iterables, optional, default=(1,0,0)
The (p,d,q) order of the model for the number of AR parameters, differences, and MA parameters.
dmust be an integer indicating the integration order of the process, whilepandqmay 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_orderiterable, optional, default=(0,0,0,0)
The (P,D,Q,s) order of the seasonal component of the model for the AR parameters, differences, MA parameters, and periodicity.
Dmust be an integer indicating the integration order of the process, whilePandQmay 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.sis 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.- trendstr{‘n’,’c’,’t’,’ct’} or iterable, optional, default=”c”
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_errorbool, optional, default=False
Whether or not to assume the endogenous observations
endogwere measured with error.- time_varying_regressionbool, optional, default=False
Used when an explanatory variables,
exog, are provided to select whether or not coefficients on the exogenous regressors are allowed to vary over time.- mle_regressionbool, optional, default=True
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_regressionis True, this must be set to False.- simple_differencingbool, optional, default=False
- 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.
- enforce_stationaritybool, optional, default=True
- Whether or not to transform the AR parameters to enforce stationarity in the autoregressive component of the model.
- enforce_invertibilitybool, optional, default=True
- Whether or not to transform the MA parameters to enforce invertibility in the moving average component of the model.
- hamilton_representationbool, optional, default=False
- Whether or not to use the Hamilton representation of an ARMA process (if True) or the Harvey representation (if False).
- concentrate_scalebool, optional, default=False
- 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_offsetint, optional, default=1
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_diffusebool, optional, default=False
- Whether or not to use exact diffuse initialization for non-stationary states. Default is False (in which case approximate diffuse initialization is used).
- dispbool, optional, default=False
- Set to True to print convergence messages.
- random_stateint, RandomState instance or None, optional, default=None
- default=None - If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.
- start_paramsarray_like, optional
- Initial guess of the solution for the loglikelihood maximization. If None, the default is given by SARIMAX.start_params.
- transformedbool, optional
Whether or not
start_paramsis already transformed. Default is True.- includes_fixedbool, optional
If parameters were previously fixed with the
fix_paramsmethod, this argument describes whether or notstart_paramsalso includes the fixed parameters, in addition to the free parameters. Default is False.- cov_typestr, optional
The
cov_typekeyword governs the method for calculating the covariance matrix of parameter estimates. Can be one of:‘opg’ for the outer product of gradient estimator
- ‘oim’ for the observed information matrix estimator, calculated
using the method of Harvey (1989)
- cov_kwdsdict or None, optional
A dictionary of arguments affecting covariance matrix computation.
opg, oim, approx, robust, robust_approx
- ‘approx_complex_step’bool, optional - If True, numerical
approximations are computed using complex-step methods. If False, numerical approximations are computed using finite difference methods. Default is True.
- ‘approx_complex_step’bool, optional - If True, numerical
- methodstr, optional
The
methoddetermines which solver fromscipy.optimizeis used, and it can be chosen from among the following strings:‘newton’ for Newton-Raphson
‘nm’ for Nelder-Mead
‘bfgs’ for Broyden-Fletcher-Goldfarb-Shanno (BFGS)
‘lbfgs’ for limited-memory BFGS with optional box constraints
‘powell’ for modified Powell’s method
‘cg’ for conjugate gradient
‘ncg’ for Newton-conjugate gradient
‘basinhopping’ for global basin-hopping solver
The explicit arguments in
fitare passed to the solver, with the exception of the basin-hopping solver. Each solver has several optional arguments that are not the same across solvers. See the notes section below (or scipy.optimize) for the available arguments and for the list of explicit arguments that the basin-hopping solver supports.- maxiterint, optional
- The maximum number of iterations to perform.
- full_outputbool, optional
- Set to True to have all available output in the Results object’s mle_retvals attribute. The output is dependent on the solver. See LikelihoodModelResults notes section for more information.
- callbackcallable callback(xk), optional
- Called after each iteration, as callback(xk), where xk is the current parameter vector.
- return_paramsbool, optional
- Whether or not to return only the array of maximizing parameters. Default is False.
- optim_score{‘harvey’, ‘approx’} or None, optional
The method by which the score vector is calculated. ‘harvey’ uses the method from Harvey (1989), ‘approx’ uses either finite difference or complex step differentiation depending upon the value of
optim_complex_step, and None uses the built-in gradient approximation of the optimizer. Default is None. This keyword is only relevant if the optimization method uses the score.- optim_complex_stepbool, optional
Whether or not to use complex step differentiation when approximating the score; if False, finite difference approximation is used. Default is True. This keyword is only relevant if
optim_scoreis set to ‘harvey’ or ‘approx’.- optim_hessian{‘opg’,’oim’,’approx’}, optional
- The method by which the Hessian is numerically approximated. ‘opg’ uses outer product of gradients, ‘oim’ uses the information matrix formula from Harvey (1989), and ‘approx’ uses numerical approximation. This keyword is only relevant if the optimization method uses the Hessian matrix.
- low_memorybool, optional
- If set to True, techniques are applied to substantially reduce memory usage. If used, some features of the results object will not be available (including smoothed results and in-sample prediction), although out-of-sample forecasting is possible. Default is False.
Examples
>>> from sktime.datasets import load_airline
>>> from sktime.forecasting.sarimax import SARIMAX
>>> y = load_airline ()
>>> forecaster = SARIMAX (
... order = (1, 0, 0), trend = "t", seasonal_order = (1, 0, 0, 6))
... )
>>> forecaster. fit (y) SARIMAX(
... )
>>> y_pred = forecaster. predict (fh = y. index)References
- [1 ] Hyndman, Rob J., and George Athanasopoulos. Forecasting: principles and practice. OTexts, 2014.