ARIMA: AR, I, and MA Components
Explore the ARIMA model's components—autoregression, integration, and moving average—and how they forecast monthly pharmacy flu-test demand. Learn to avoid time leakage by keeping test data unseen and use RMSE to compare ARIMA forecasts with naive baselines. Understand how model orders affect predictions and prepare for selecting optimal parameters using ACF, PACF, and information criteria.
We'll cover the following...
Monthly pharmacy flu-test demand determines how many kits to stock before the next month begins. Stocking fewer kits than demand creates costly stockouts, while stocking too many ties up inventory. For the 36 monthly counts in this example, we forecast the months after the training window and score the forecasts on the final six months.
The current rule uses the last observed demand as every future forecast in the six-month test period. This naive forecast gives us a minimum comparison point. A model only earns its extra complexity when it improves on that rule for the held-out months.
The first 30 months form the training window. The final six months remain unseen until scoring. Using sales from those six future months to choose model settings or estimate model parameters would be time leakage, because the forecast would draw on information unavailable at its prediction date.
The following pipeline creates the monthly series, applies the last-value baseline, and reports root mean squared error (RMSE) on the six held-out months.
Lines 12 and 56: The demand is a single ordered pandas
Seriesindexed by a monthlyDatetimeIndex(freq="MS"), matching the course’s earlier “time order matters” setup for time-series splits.Lines 58–66: The chronological split keeps the final six months fully held out (avoiding time leakage), and the naive baseline is a constant forecast equal to the last training value (month 30).
Lines 5–7 and 68: RMSE is computed directly from the six test-month errors as
...