mojolearn.AutoARIMA#
- class mojolearn.AutoARIMA(endog)[source]#
Bases:
objectAutomatic ARIMA order selection for a batch of series.
Chooses, per series, the differencing order
dby the KPSS test and then the (p, q, P, Q) orders and intercept with the least information criterion, following cuML’sAutoARIMA.search; fit() then fits each chosen model withARIMA. Every candidate order is fitted on all the series that share adas one batch; on a tie the first order tried wins.endogis laid out one series per row,(batch_size, n_obs); cuML’s AutoARIMA takes series in columns, so transpose to call it the same way. Fitting is maximum likelihood only.- Parameters:
endog (array-like of shape (batch_size, n_obs) or (n_obs,)) – The series, float32. float64 raises TypeError.
- Variables:
d_ (ndarray of shape (batch_size,), int64) – Differencing order chosen for each series. Set by search().
order_ (ndarray of shape (batch_size, 8), int64) – Chosen
(p, d, q, P, D, Q, s, k)per series,k1 with an intercept. Set by search().ic_ (ndarray of shape (batch_size,), float64) – Information criterion of the chosen order. Set by search().
models (list) – Distinct chosen models as
((p, d, q), (P, D, Q, s), k).
Examples
>>> import numpy as np, mojolearn >>> y = np.random.default_rng(0).standard_normal((8, 120)).cumsum(axis=1).astype(np.float32) >>> model = mojolearn.AutoARIMA(y).search(d=range(2), p=range(3), q=range(3)).fit() >>> model.forecast(10).shape (8, 10)
Methods
fit([h, maxiter, method, truncate])Fit the chosen model of every series.
forecast(nsteps[, level])Forecast
nstepspast the end of every series.predict([start, end, level])In-sample (and out-of-sample) predictions from
starttoend.search([s, d, D, p, q, P, Q, fit_intercept, ...])Select the orders for every series.
- search(s=None, d=range(0, 3), D=range(0, 2), p=range(1, 4), q=range(1, 4), P=range(0, 3), Q=range(0, 3), fit_intercept='auto', ic='aicc', test='kpss', seasonal_test='seas', h=1e-08, maxiter=20, method='auto', truncate=0)[source]#
Select the orders for every series.
- Parameters:
s (int or None, default None) – Seasonal period. None, 0 or 1 means non-seasonal (then D, P and Q are 0).
d (int or iterable of int, default range(3)) – Differencing options; a list must be
0, 1, ..., d_max. With one value it is used for every series; otherwise the KPSS test picksdper series.D (int or iterable of int, default range(2)) – Seasonal differencing; with
sset, give one value (the seasonal test over several values is not supported).p, q (int or iterable of int, default range(1, 4)) – Non-seasonal AR and MA order options, clipped to [0, 4] (or [0, s - 1] when seasonal).
P, Q (int or iterable of int, default range(3)) – Seasonal AR and MA order options, clipped to [0, 4] (0 when non-seasonal).
fit_intercept (bool or “auto”, default “auto”) – Whether candidates include an intercept.
ic ({“aic”, “aicc”, “bic”}, default “aicc”) – Information criterion.
test ({“kpss”}, default “kpss”) – Stationarity test for
d.seasonal_test (str, default “seas”) – Only used with several
Doptions, which are not supported.h (float, default 1e-8) – Only the default is supported.
maxiter (int, default 20) – Optimizer iterations per candidate fit.
method ({“auto”, “ml”}, default “auto”) – Fitting method; maximum likelihood.
"css"and"css-ml"raise NotImplementedError.truncate (int, default 0) – Only 0 is supported.
- Returns:
self
- Raises:
ValueError – For an unknown
icortest, or an order option with no valid value.NotImplementedError – For css methods, a non-default
hortruncate, severalDoptions with a season, or adlist that is not0..d_max.
- fit(h=1e-08, maxiter=1000, method='ml', truncate=0)[source]#
Fit the chosen model of every series.
Call search() first.
- Parameters:
h (float, default 1e-8) – Only the default is supported.
maxiter (int, default 1000) – Optimizer iterations.
method ({“ml”}, default “ml”) – Maximum likelihood only.
truncate (int, default 0) – Only 0 is supported.
- Returns:
self
- Raises:
RuntimeError – If search() has not been called.
- predict(start=0, end=None, level=None)[source]#
In-sample (and out-of-sample) predictions from
starttoend.- Parameters:
start (int, default 0) – First index to predict.
end (int or None, default None) – One past the last index; None means
n_obs.level (None) – Prediction intervals are not supported; anything other than None raises NotImplementedError.
- Returns:
ndarray of shape (batch_size, end - start), float32