Contents
- Which Python packages are required?
- Step 1: import the data
- Step 2: plot the series with a rolling mean and standard deviation
- Step 3: test stationarity with the ADF test
- Step 4: decompose trend and seasonality
- Step 5: run auto ARIMA
- Step 6: forecast and evaluate accuracy
- When should auto ARIMA not be trusted blindly?
- How to read the auto_arima summary
- Comparing auto ARIMA with a manually identified SARIMA
- How to report an auto ARIMA model
- Frequently asked questions
- What is the difference between ARIMA and auto ARIMA?
- Does auto ARIMA handle seasonal data?
- How many observations does auto ARIMA need?
- Why does pmdarima fail to install?
- Is auto ARIMA accepted in academic research?
- Why does auto ARIMA choose a different model each time the data are updated?
- Should the stepwise search be turned off?
- References
Versi bahasa Indonesia: Auto ARIMA dalam Python: Simple dan Akurat
Short answer: auto ARIMA in Python, available as auto_arima in the pmdarima package, searches many ARIMA or SARIMA specifications and selects the one with the lowest information criterion (AIC by default). It decides the differencing order with a statistical unit root test instead of visual judgment, then fits and forecasts the chosen model. A complete workflow takes six steps: import the data, plot it, test stationarity with the Augmented Dickey-Fuller (ADF) test, decompose trend and seasonality, run auto_arima, and evaluate the forecast on a holdout sample.
The classical Box-Jenkins approach relies heavily on visual judgment. A researcher decides whether a plot looks stationary and whether the ACF and PACF “cut off” or “die down”. Nothing is wrong with that approach. However, two analysts may read the same plot differently, and academic reviewers increasingly prefer decisions backed by a test statistic. Auto ARIMA replaces those judgment calls with formal tests and information criteria, and Python performs the work at no license cost.
Which Python packages are required?
The workflow uses five packages: pandas for data handling, matplotlib and seaborn for plots, statsmodels for the ADF test and decomposition, and pmdarima for the automated search. Install them from the command prompt:
pip install pandas matplotlib seaborn statsmodels pmdarima
When this workflow was first tested in November 2022, pmdarima could not be installed on the newest Python release at that time (3.11), so Python 3.8 was used instead. Compatibility has improved since then, but a version mismatch between pmdarima, NumPy, and Python remains the most common installation error. When it occurs, creating a separate virtual environment with a slightly older Python version usually resolves it.
Step 1: import the data
The example file Data.csv has two columns: date, an observation index, and data, the values to be forecast. The example series consists of daily closing prices of a stock.
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("Data.csv")
y = df["data"]
print(df.head())
print(df.tail())
Step 2: plot the series with a rolling mean and standard deviation
roll = y.rolling(window=12)
plt.figure(figsize=(10, 4))
plt.plot(y, label="Data")
plt.plot(roll.mean(), label="Rolling mean")
plt.plot(roll.std(), label="Rolling std")
plt.legend()
plt.savefig("rolling.png")
plt.show()

The plot reveals a clear upward trend and strong fluctuations in the rolling standard deviation, particularly between observations 150 and 250. Both features suggest that the series is not stationary and may contain a repeating pattern.
Step 3: test stationarity with the ADF test
The Augmented Dickey-Fuller test formalizes the visual impression. The null hypothesis states that the series has a unit root (not stationary); the alternative states that the series is stationary. The null is rejected when the p-value is below 0.05.
from statsmodels.tsa.stattools import adfuller
adft = adfuller(y, autolag="AIC")
out = pd.DataFrame({
"Values": [adft[0], adft[1], adft[2], adft[3],
adft[4]["1%"], adft[4]["5%"], adft[4]["10%"]],
"Metric": ["Test statistic", "p-value", "Lags used", "Observations used",
"Critical value (1%)", "Critical value (5%)", "Critical value (10%)"]
})
print(out)
For the example series, the p-value equals 0.91. Thus, the null hypothesis is not rejected, and the series is not stationary. In manual Box-Jenkins modeling, the next step would be differencing. With auto ARIMA, the differencing order is determined automatically in Step 5.
Step 4: decompose trend and seasonality
from statsmodels.tsa.seasonal import seasonal_decompose
result = seasonal_decompose(y, model="additive", period=15)
result.plot()
plt.savefig("decomposition.png")
plt.show()
The period argument is a hypothesis about the length of one seasonal cycle. Quarterly data with an annual cycle would use 4, monthly data would use 12, and daily trading data might use 5 for a weekly cycle. Choosing the period requires knowledge of how the data were generated; the decomposition then shows whether the seasonal component is strong enough to justify a seasonal model.

Step 5: run auto ARIMA
The data are split into a training set and a test set so that forecast accuracy can be measured on observations the model has never seen.
import pmdarima as pm
n_test = 20
train, test = y[:-n_test], y[-n_test:]
model = pm.auto_arima(
train,
start_p=0, start_q=0, max_p=5, max_q=5,
d=None, # let the ADF test choose d
test="adf",
seasonal=True, m=15, # seasonal period from Step 4
start_P=0, D=None,
information_criterion="aic",
stepwise=True, trace=True,
error_action="ignore", suppress_warnings=True
)
print(model.summary())
With trace=True, every candidate model is printed with its AIC, which documents the search for a thesis or report. The summary table shows the selected order, for example ARIMA(1,1,1)(0,0,1)[15], the estimated coefficients and their p-values, and the Ljung-Box and Jarque-Bera tests on the residuals. A Ljung-Box p-value above 0.05 indicates that the residuals are free of autocorrelation.
Step 6: forecast and evaluate accuracy
import numpy as np
fc, conf = model.predict(n_periods=n_test, return_conf_int=True)
mape = np.mean(np.abs((test.values - fc) / test.values)) * 100
print(f"MAPE: {mape:.2f}%")
plt.figure(figsize=(10, 4))
plt.plot(range(len(train)), train, label="Train")
idx = range(len(train), len(y))
plt.plot(idx, test, label="Actual")
plt.plot(idx, fc, label="Forecast")
plt.fill_between(idx, conf[:, 0], conf[:, 1], alpha=0.2)
plt.legend()
plt.show()
A MAPE below 10 percent is usually considered highly accurate, 10 to 20 percent good, and above 50 percent poor. Once the accuracy is acceptable, the model can be refitted on the full series with model.update(test) before forecasting future periods.
When should auto ARIMA not be trusted blindly?
Automation does not remove the need for judgment. Firstly, the seasonal period m must still be supplied by the analyst. Secondly, stepwise search may miss the global optimum, so setting stepwise=False is worth trying for important models despite the longer runtime. Thirdly, financial series often show volatility clustering, in which case the residual variance is not constant and an ARCH or GARCH model should be considered after ARIMA. Finally, the selected model must make economic or agronomic sense.
How to read the auto_arima summary
The summary() output of pmdarima follows the statsmodels SARIMAX format. The header reports the selected order, for example SARIMAX(1, 1, 1)x(0, 1, 1, 12), together with the log likelihood, AIC, BIC, and HQIC. The coefficient table lists each parameter: ar.L1 for the non-seasonal autoregressive term, ma.L1 for the non-seasonal moving average term, ma.S.L12 for the seasonal moving average term, and sigma2 for the residual variance. A coefficient with p < 0.05 contributes significantly to the model. However, a non-significant coefficient does not automatically mean the term should be removed, since auto ARIMA selects the order based on AIC for the whole model rather than on individual p-values.
The lower part of the summary is equally important. The Ljung-Box (Q) statistic tests whether residuals are still autocorrelated; a p-value above 0.05 indicates that the residuals behave like white noise. The Jarque-Bera test checks residual normality, and the heteroskedasticity test (H) checks whether residual variance changes over time. When the H test is significant, the point forecast may still be usable, but the prediction intervals become unreliable. Thus, an ARCH or GARCH model may be needed for the variance.
Comparing auto ARIMA with a manually identified SARIMA
A useful exercise is to compare the auto ARIMA result with the model suggested by the ACF and PACF. In one monthly sales dataset of 72 observations, the ACF and PACF suggested SARIMA(0,1,1)(0,1,1)12, while auto ARIMA selected SARIMA(1,1,1)(0,1,1)12. The AIC difference was only 1.8 points, and the hold-out mean absolute percentage error (MAPE) for the last 12 months was 6.4% and 6.1%, respectively. Both models were therefore practically equivalent. Consequently, auto ARIMA is best treated as a fast and reproducible starting point, while the manual identification provides the reasoning that examiners and reviewers usually expect.
A small analogy helps explain this relationship. A navigation application proposes the fastest route, yet a driver who knows the city still checks whether the route passes a market that is congested every Friday. Auto ARIMA is the application; knowledge of the data is the driver.
How to report an auto ARIMA model
A report should state the package and version, the search ranges (for example p and q from 0 to 3, P and Q from 0 to 2, m = 12), the information criterion used, and the final order. The accuracy on a hold-out sample (MAPE, RMSE) and the Ljung-Box result should follow. For example: “The model was selected using pmdarima 2.0 with a stepwise search minimizing AIC. The selected SARIMA(1,1,1)(0,1,1)12 produced a hold-out MAPE of 6.1%, and the Ljung-Box test indicated no remaining autocorrelation (Q = 14.2; p = 0.29).”
Related guides on Catatan Budi: ACF and PACF for SARIMA, ARCH and GARCH models, Granger causality test.
Frequently asked questions
What is the difference between ARIMA and auto ARIMA?
ARIMA is the model itself. Auto ARIMA is a procedure that searches for the best ARIMA orders automatically using unit root tests and information criteria.
Does auto ARIMA handle seasonal data?
Yes. Setting seasonal=True and a seasonal period m makes auto ARIMA search SARIMA specifications as well.
How many observations does auto ARIMA need?
A practical minimum is about 50 observations for a non-seasonal model and at least three or four full seasonal cycles for a seasonal model.
Why does pmdarima fail to install?
Most failures come from incompatible versions of Python, NumPy, and pmdarima. Installing into a fresh virtual environment with a supported Python version usually fixes the error.
Is auto ARIMA accepted in academic research?
Yes, provided the report states the search range, the information criterion, the selected model, and the residual diagnostics.
Why does auto ARIMA choose a different model each time the data are updated?
Each new observation changes the likelihood and the information criteria slightly. When two candidate models have AIC values within one or two points, a small update can reverse the ranking. Such models usually forecast almost identically, so the change is rarely a problem in practice.
Should the stepwise search be turned off?
The stepwise search is fast and usually finds a good model. Setting stepwise=False runs an exhaustive grid search, which takes longer but guarantees that every combination within the specified ranges is compared.
References
- Hyndman, R. J., and Khandakar, Y. (2008). Automatic time series forecasting: The forecast package for R. Journal of Statistical Software, 27(3), 1–22.
- Smith, T. G., et al. pmdarima: ARIMA estimators for Python. alkaline-ml.com/pmdarima.
- Dickey, D. A., and Fuller, W. A. (1979). Distribution of the estimators for autoregressive time series with a unit root. Journal of the American Statistical Association, 74(366), 427–431.
Discussion
No comments yet. Have a question about this topic? Write it below and I will do my best to answer.