If you are not a magician who can easily infer correct SARIMAX orders from looking on PACF (partial autocorrelation function) and ACF (autocorrelation function), you want to rather leverage AutoSarima which finds them for you - set init_with_autoarima
to True.
If you want to further configure the search space of AutoARIMA, then you can provide all parameters of pmdarima.arima.AutoARIMA as autoarima_dict
arguments.
When you run cross-validation with enabled AutoARIMA (init_with_autoarima
), it's often advisable to find the correct order only during the first fit call and reuse this model on all other splits in order to simulate the out-of-sample performance.
The signature of SarimaxWrapper contains parameters of pmdarima.arima.ARIMA, not AutoARIMA class.
For more parameters check pmdarima docs
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn')
plt.rcParams['figure.figsize'] = [12, 6]
from hcrystalball.utils import get_sales_data
df = get_sales_data(n_dates=100,
n_assortments=1,
n_states=1,
n_stores=1)
X, y = df[["Open"]], df['Sales']
X
from hcrystalball.wrappers import SarimaxWrapper
SarimaxWrapper?
model = SarimaxWrapper(
autoarima_dict={'d':1, 'm':7, 'max_p':2, 'max_q':2},
init_with_autoarima=True
)
preds = (model.fit(X[:-10], y[:-10])
.predict(X[-10:])
.merge(y, left_index=True, right_index=True, how='outer')
.tail(50)
)
preds.plot(title=f"MAE:{(preds['Sales']-preds['sarimax']).abs().mean().round(3)}");
And now access the models parameters
model
You might also directly pass the orders if you know, what are you doing
model = SarimaxWrapper(order=(1, 1, 2), seasonal_order=(1, 0, 2, 7))
preds = (model.fit(X[:-10], y[:-10])
.predict(X[-10:])
.merge(y, left_index=True, right_index=True, how='outer')
.tail(50)
)
preds.plot(title=f"MAE:{(preds['Sales']-preds['sarimax']).abs().mean().round(3)}");
model
model