AI & Machine Learning Master Course — 144. Autoregressive and classical forecasting models
Smartyfy AI & Machine Learning Master Course
Course ID: smartyfy-ai-ml-master-200
Lesson 144: Autoregressive and classical forecasting models
Prerequisites: Lesson 143. Learning outcome: Fit appropriate autoregressive models and check their assumptions.
Regress a series on its own past
An autoregressive model predicts a value from earlier values of the same series. An AR(p) model uses p lags with shared coefficients. For AR(1), write y_t=c+phi*y_previous+innovation_t. The innovation represents new variation not predicted from the modeled past.
A forecasting interpretation usually assumes future innovations have conditional mean zero. The one-step point forecast is therefore c+phi*y_latest. That assumption is substantive: if residuals contain a systematic pattern, the model may be missing information that would improve forecasts.
An autoregressive coefficient describes dependence under the fitted model, not the causal effect of intervening on yesterday’s outcome. Common drivers, measurement rules, and omitted variables can produce temporal association. Use the model for its stated prediction task without converting its coefficients into unsupported causal claims.
Understand stability before extrapolating
For a scalar AR(1) with suitable innovations, absolute phi below one permits a stationary solution. Its long-run mean is c/(1−phi). Positive phi below one tends to carry deviations forward with gradual decay; negative phi can alternate deviations around the mean.
At phi equal to one, the process has random-walk behavior under the usual setup rather than reverting to a fixed stationary mean. The formula c/(1−phi) is then undefined. For higher-order autoregressions, checking every coefficient separately is insufficient; stationarity depends on the roots of the characteristic polynomial.
Stationarity concerns distributional properties over time, not the absence of every visible fluctuation. A fitted coefficient satisfying a stability condition is not a statistical proof that observed data are stationary. Trends, breaks, changing variance, and initial transients can still matter for the experiment.
Recursive forecasts must use predictions beyond the origin
From one fixed origin, forecast the next value with the last observed value. For the second step, use the first forecast in place of the unavailable future observation. Continue recursively. Substituting actual future values at later steps instead evaluates a sequence of updated one-step forecasts, which is a different task.
For stable AR(1), the h-step conditional mean can also be written as mu+phi^h*(y_latest−mu), where mu=c/(1−phi). This provides an independent arithmetic check on recursive code. Prediction intervals require assumptions about innovation variation and parameter uncertainty; a point path alone does not quantify either.
Do not infer that a smooth multi-step forecast means the actual future will be smooth. The path describes conditional means while future innovations remain unknown. Actual observations can fluctuate substantially around it.
CPU lab: estimate a small AR(1) and forecast five steps
The fictional generator uses intercept one, coefficient 0.7, and Gaussian innovation standard deviation 0.2. It starts from zero, so the initial value is not a draw from the stationary distribution. The experiment creates 140 values and fits an intercept plus one lag on the first hundred.
Ordinary least squares gives intercept approximately 1.045458 and coefficient 0.673646. Their implied stationary mean is about 3.203446. From the final training observation, the five recursive forecasts are approximately [3.095960,3.131039,3.154669,3.170587,3.181311]. Their MAE against the next five outcomes is 0.293259.
Only the training prefix is fitted. The recursion never reads future realized values. Assertions check the estimated stability condition and the second-step recurrence. These checks validate this simple implementation; they do not establish that one short test window is a robust estimate of general forecasting performance.
import numpy as np
rng=np.random.default_rng(144)
y=np.zeros(140)
for t in range(1,len(y)): y[t]=1+.7*y[t-1]+rng.normal(0,.2)
train=y[:100]
X=np.column_stack([np.ones(99),train[:-1]])
c,phi=np.linalg.lstsq(X,train[1:],rcond=None)[0]
# Fixed-origin recursive path: no future realized y enters predictions.
state=train[-1]; pred=[]
for _ in range(5):
state=c+phi*state; pred.append(state)
print('Intercept / AR coefficient:',round(float(c),6),round(float(phi),6))
print('Five-step forecast:',np.round(pred,6).tolist())
print('Five-step MAE:',round(float(np.mean(abs(np.array(pred)-y[100:105]))),6))
print('Implied stationary mean:',round(float(c/(1-phi)),6))
assert abs(phi)<1 and np.isfinite(pred).all()
assert np.isclose(pred[1],c+phi*pred[0])
Place autoregression among classical alternatives
ARIMA models combine autoregressive terms, differencing, and moving-average terms based on past innovations. The moving-average part of ARIMA is not the trailing arithmetic average baseline from Lesson 142. The shared name refers to different mathematical constructions.
Differencing transforms changes rather than levels and can help address some nonstationary patterns, but excessive differencing can introduce unnecessary complexity. Exponential-smoothing models offer another approach by updating estimates of level, trend, or seasonality. These families should be chosen and evaluated under the same temporal information contract.
This lesson executes only the NumPy AR(1) regression. It does not run an automatic ARIMA search, fit an exponential-smoothing package, or perform formal stationarity tests. The broader methods are conceptual context for selecting suitable later experiments.
Diagnose and compare before trusting the forecast
Inspect residual bias, autocorrelation, changing spread, and large errors. Residual checks help identify problems; passing a few diagnostics does not certify future stability. Compare with naive and seasonal baselines across multiple chronological origins.
Select lag order and transformations using development backtests. Refit according to the intended operational schedule, and record how late or revised observations are handled. A classical model can be simple and effective, but its evaluation still needs the same discipline as a larger neural system.
Four practice questions with worked answers
Practice 1
For c=1, phi=0.5, and latest value 4, find the next two fixed-origin forecasts.
Answer: The first is 1+0.5×4=3. The second uses that forecast: 1+0.5×3=2.5. Using the actual next observation for the second step would change the evaluation protocol.
Practice 2
Find the stationary mean for c=2 and phi=0.8 under the AR(1) assumptions.
Answer: The mean is 2/(1−0.8)=10. This formula requires a suitable stable process; at phi=1 its denominator would be zero.
Practice 3
Does checking each AR(2) coefficient is below one prove stationarity?
Answer: No. Higher-order stability depends on the joint characteristic roots, not independent bounds on each coefficient. Use the appropriate model conditions rather than extending the AR(1) rule incorrectly.
Practice 4
How does an ARIMA moving-average term differ from a trailing mean?
Answer: The ARIMA term combines past innovations or forecast errors under the model. A trailing mean directly averages past observed values. They are different operations despite sharing the phrase moving average.
Five multiple-choice questions
Question 1
What does an AR(1) one-step conditional-mean forecast omit?
- A. The unknown future innovation, assumed to have conditional mean zero.
- B. The latest observed value even when it is available.
- C. The fitted intercept by definition.
Correct: A. The future innovation is not observed and contributes zero to the assumed conditional mean. The lagged value and intercept remain in the forecast.
Question 2
Which scalar AR(1) coefficient supports a stationary solution under standard assumptions?
- A. 0.7
- B. 1.0
- C. 1.2
Correct: A. Absolute coefficient below one is the relevant AR(1) stability condition. The unit-root and explosive examples have different behavior.
Question 3
What enters the second recursive forecast from a fixed origin?
- A. The average of all future realized values.
- B. The actual next observation from the held-out period.
- C. The first forecast in place of the unavailable next observation.
Correct: C. Fixed-origin recursion cannot use new realized outcomes. Using them would evaluate an updated forecast task or leak future information.
Question 4
What is actually fitted in the lab?
- A. An exponential-smoothing state-space model.
- B. An intercept and one lag coefficient by least squares.
- C. An automatic search over all seasonal ARIMA orders.
Correct: B. The executed design has two columns and a one-step target. The other model families are discussed but not run.
Question 5
What does a smooth multi-step mean path imply?
- A. Actual future observations must lie exactly on that path.
- B. The model’s conditional means evolve smoothly under zero-mean future innovations.
- C. Prediction intervals have zero width whenever phi is below one.
Correct: B. Point forecasts summarize conditional means. Unknown innovations still create uncertainty and observed fluctuations.
Common pitfalls
Avoid confusing autoregressive association with causality, applying scalar stability rules to higher orders, feeding actual future values into fixed-origin recursion, or calling a rolling mean an ARIMA innovation model.
Summary
Autoregression makes temporal dependence explicit through lagged values. Stability, recursive information flow, residual checks, and realistic backtests determine whether the resulting point forecasts are interpretable and useful.