kats.models.sarima module¶

class kats.models.sarima.SARIMAModel(data: kats.consts.TimeSeriesData, params: kats.models.sarima.SARIMAParams)[source]¶

Bases: Generic[kats.models.model.ParamsType]

Model class for SARIMA.

This class provides fit, predict and plot methods for SARIMA model.

data¶

kats.consts.TimeSeriesData object for input time series.

params¶

SARIMAParams for model parameters.

fit(start_params: Optional[numpy.ndarray] = None, transformed: bool = True, includes_fixed: bool = False, cov_type: Optional[str] = None, cov_kwds: Optional[Dict] = None, method: str = 'lbfgs', maxiter: int = 50, full_output: bool = True, disp: bool = False, callback: Optional[Callable] = None, return_params: bool = False, optim_score: Optional[str] = None, optim_complex_step: bool = True, optim_hessian: Optional[str] = None, low_memory: bool = False)None[source]¶

Fit SARIMA model by maximum likelihood via Kalman filter.

See reference https://www.statsmodels.org/stable/generated/statsmodels.tsa.statespace.sarimax.SARIMAX.fit.html#statsmodels.tsa.statespace.sarimax.SARIMAX.fit for more details.

Parameters
  • start_params – Optional; An array_like object for the initial guess of the solution for the loglikelihood maximization.

  • transformed – Optional; A boolean to specify whether or not start_params is already transformed. Default is True.

  • includes_fixed – Optional; A boolean to specify whether or not start_params includes the fixed parameters in addition to the free parameters. Default is False.

  • cov_type – Optional; A string for the method for calculating the covariance matrix of parameter estimates. Can be ‘opg’ (outer product of gradient estimator), ‘oim’ (observed information matrix estimato), ‘approx’ (observed information matrix estimator), ‘robust’ (approximate (quasi-maximum likelihood) covariance matrix), or ‘robust_approx’. Default is ‘opg’ when memory conservation is not used, otherwise default is ‘approx’.

  • cov_kwds – Optional; A dictionary of arguments for covariance matrix computation. See reference for more details.

  • method – Optional; A string for solver from scipy.optimize to be used. Can be ‘newton’, ‘nm’, ‘bfgs’, ‘lbfgs’, ‘powell’, ‘cg’, ‘ncg’ or ‘basinhopping’. Default is ‘lbfgs’.

  • maxiter – Optional; An integer for the maximum number of iterations to perform. Default is 50.

  • full_output – Optional; A boolean to specify whether or not to have all available output in the Results object’s mle_retvals attribute. Default is True.

  • disp – Optional; A boolean to specify whether or not to print convergence messages. Default is False.

  • callback – Optional; A callable object to be called after each iteration. Default is None.

  • return_params – Optional; A boolean to specify whether or not to return only the array of maximizing parameters. Default is False.

  • optim_score – Optional; A string for the method by which the score vector is calculated. Can be ‘harvey’, ‘approx’ or None. Default is None.

  • optim_complex_step – Optional; A boolean to specify whether or not to use complex step differentiation when approximating the score. Default is True.

  • optim_hessian – Optional; A string for the method by which the Hessian is numerically approximated. Can be ‘opg’, ‘oim’, ‘approx’. Default is None.

  • low_memory – Optional; A boolean to specify whether or not to reduce memory usage. If True, some features of the results object will not be available. Default is False.

Returns

None.

static get_parameter_search_space()List[Dict[str, Union[List[Any], bool, str]]][source]¶

Get default SARIMA parameter search space.

Returns

A dictionary representing the default SARIMA parameter search space.

plot()[source]¶

Plot forecasted results from SARIMA model.

predict(steps: int, include_history: bool = False, alpha: float = 0.05, **kwargs)pandas.core.frame.DataFrame[source]¶

Predict with fitted SARIMA model.

Parameters
  • steps – An integer for forecast steps.

  • include_history – Optional; A boolearn to specify whether to include historical data. Default is False.

  • alpha – A float for confidence level. Default is 0.05.

Returns

A pandas.DataFrame of forecasts and confidence intervals.

class kats.models.sarima.SARIMAParams(p: int, d: int, q: int, exog=None, seasonal_order: Tuple = (0, 0, 0, 0), trend=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: int = 1, use_exact_diffuse: bool = False, **kwargs)[source]¶

Bases: kats.consts.Params

Parameter class for SARIMA model

This is the parameter class for SARIMA model, it contains all necessary parameters as defined in SARIMA model implementation: https://www.statsmodels.org/stable/generated/statsmodels.tsa.statespace.sarimax.SARIMAX.html.

p¶

An integer for trend autoregressive (AR) order.

d¶

An integer for trend difference order.

q¶

An integer for trend moving average (MA) order.

exog¶

Optional; An array of exogenous regressors.

seasonal_order¶

Optional; A tuple for (P,D,Q,s) order of the seasonal component for AR order, difference order, MA order, and periodicity. Default is (0,0,0,0).

trend¶

Optional; A string or an iterable for deterministic trend. Can be ‘c’ (constant), ‘t’ (linear trend with time), ‘ct’ (both constant and linear trend), or an iterable of integers defining the non-zero polynomial exponents to include. Default is None (not to include trend).

measurement_error¶

Optional; A boolean to specify whether or not to assume the observed time series were measured with error. Default is False.

time_varying_regression¶

Optional; A boolean to specify whether or not coefficients on the regressors (if provided) are allowed to vary over time. Default is False.

mle_regression¶

Optional; A boolean to specify whether or not to estimate coefficients of regressors as part of maximum likelihood estimation or through Kalman filter. If time_varying_regression is True, this must be set to False. Default is True.

simple_differencing¶

Optional; A boolean to specify whether or not to use partially conditional maximum likelihood estimation. See https://www.statsmodels.org/stable/generated/statsmodels.tsa.statespace.sarimax.SARIMAX.html for more details. Default is False.

enforce_stationarity¶

Optional; A boolean to specify whether or not to transform the AR parameters to enforce stationarity in AR component. Default is True.

enforce_invertibility¶

Optional; A boolean to specify whether or not to transform the MA parameters to enforce invertibility in MA component. Default is True.

hamilton_representation¶

Optional; A boolean to specify whether or not to use the Hamilton representation or the Harvey representation (if False). Default is False.

concentrate_scale¶

Optional; A boolean to specify whether or not to concentrate the scale (variance of the error term) out of the likelihood. Default is False.

trend_offset¶

Optional; An integer for the offset at which to start time trend value. Default is 1.

use_exact_diffuse¶

Optional; A boolean to specify whether or not to use exact diffuse initialization for non-stationary states. Default is False.

validate_params()[source]¶

Not implemented.