Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To create an ARIMA forecast in Python, prepare a chronologically ordered time series, choose a data-appropriate (p,d,q) order, fit statsmodels’ ARIMA model, and test forecasts against a later period the model did not see during fitting. The right order depends on the series; there is no universally correct default.

What ARIMA means in statsmodels

ARIMA combines three components: autoregression (AR), differencing (I, for integration), and moving average (MA). In statsmodels, the main interface is statsmodels.tsa.arima.model.ARIMA. Its order=(p,d,q) argument sets the autoregressive order p, differencing order d, and moving-average order q. The class also supports AR, MA, ARMA, seasonal ARIMA, and regression models with ARIMA errors. See the statsmodels ARIMA API.

  • p controls how many lagged observations contribute to the autoregressive component.
  • d specifies the differencing order used to address stochastic trend or seasonality when pursuing stationarity.
  • q controls how many lagged forecast errors contribute to the moving-average component.

These values are model choices, not settings to copy blindly. In particular, select d by examining the series and its stationarity behavior rather than automatically differencing every series or assuming a fixed value.

Prepare and inspect the time series

Load the observations, sort them into chronological order, and use a consistent date index if dates are available. A meaningful frequency matters when you want to specify forecast ranges using dates. Plot the values and look for trends, changing levels, possible seasonality, and missing observations. This inspection helps guide a model specification; it does not prove that an ARIMA model will be adequate.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For seasonal patterns, statsmodels provides seasonal_order=(P,D,Q,s). External predictors can be supplied as exog. Include either only when the series and forecasting task justify them; a forecast that uses external regressors will require corresponding future regressor values.

Split the series without breaking chronology

Reserve a final, contiguous segment of observations as a holdout set. Fit candidate models on the earlier segment and compare their forecasts with the later observations. Do not randomly shuffle a time series into training and test sets: that breaks the time order. The statsmodels ARIMA tutorial recommends testing forecasts on data set aside from model fitting and cautions against overly complex orders.

Fit a baseline ARIMA model

After choosing illustrative values based on your data, fit the model on the training segment. In this schematic example, replace p, d, and q with integer choices you have evaluated, and set horizon to the number of future observations you intend to forecast.

from statsmodels.tsa.arima.model import ARIMA

# train is the chronological training segment of a pandas Series
model = ARIMA(train, order=(p, d, q))
results = model.fit()

# Forecast horizon future observations
forecast_result = results.get_forecast(steps=horizon)
mean_forecast = forecast_result.predicted_mean
interval = forecast_result.conf_int()

The order in this example is deliberately symbolic: neither it nor a particular horizon is a recommendation for every dataset. Fit output is one part of the assessment. Inspect residual behavior, then test predictions on the held-out tail. Increasing p or q just to improve in-sample fit can create an unnecessarily complex model that does not forecast well.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the prediction method for the question

The statsmodels tutorial distinguishes the prediction interfaces by use: forecast() is a straightforward way to obtain future out-of-sample forecasts, predict() requests a specified range of in-sample or out-of-sample results, and get_forecast() returns a richer future-forecast result with confidence intervals. For ranges that may include existing observations and future dates, ARIMAResults.get_prediction(start, end, ...) supports positions, strings, or datetimes in supported cases and returns prediction results that include confidence intervals. See the get_prediction API.

One date-index caveat: if the index has no fixed frequency, use an integer index for end when requesting out-of-sample predictions. If the model includes exogenous regressors, provide the matching future regressors when the prediction call requires them; the API exposes an exog parameter.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Evaluate candidates on held-out forecasts

Compare candidate specifications on the same chronological holdout and forecast horizon. Choose an error metric that makes sense for the scale of the series and the cost of forecast errors in your application; the documentation does not prescribe one universally best metric or threshold. Also review residual autocorrelation, stability, convergence, model complexity, and—if uncertainty matters—interval width and calibration. A narrow interval is not automatically a better forecast, and an interval is not a guarantee that the actual value will fall inside it.

For broader context on statsmodels’ time-series tools and prediction results, see its time-series overview.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Refit for a production forecast

Once validation supports a defensible baseline, refit the chosen specification using the appropriate history available for the real forecasting task, then request the number of future steps needed. A successful fit and a holdout result do not guarantee future accuracy: monitor performance as new observations arrive and revisit the specification if the series changes.

The implementation details here follow the statsmodels stable documentation identified as version 0.15.0, accessed October 4, 2026. API details can change, so consult the live documentation when applying the code to a different release.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.