JA EN
LearnTime Series
·★ MEMBER·9 min read

Time-Series Forecasting from Scratch — From Classical Methods to Foundation Models

What makes forecasting different from ordinary regression is that the rows are not independent and the test set is always in the future. Autocorrelation and stationarity first, then the intuition behind ARIMA, seasonal and trend decomposition, and where deep and foundation models actually sit. The last third is evaluation — no random splits, how to backtest, and why MAPE lies.


What makes this different from ordinary regression

"Predict tomorrow's sales from sales up to today." It looks like plain regression, and any learning library will happily print a number. That validation score will almost certainly be better than production. Time series lack all four properties that ordinary supervised learning quietly assumes.

Rows are not independent. Standard learning assumes samples are drawn independently from the same distribution. In a time series, two adjacent points carry almost the same information. Know today's temperature and you already half-know tomorrow's.

Order carries meaning. Shuffle the rows of an image dataset and nothing is lost. Shuffle a time series and the information itself disappears.

The distribution moves. Mean and variance both drift. Last year's demand level is not this year's demand level.

The future leaks in easily. The moment you engineer a feature like "7-day moving average", you create room for values the model could not have known at prediction time. That accident gets a section of its own at the end.

Autocorrelation: your own past is the strongest feature

Shift a series by kk steps, compare it against itself, and the correlation you get is the autocorrelation at lag kk.

ρk=Cov(yt, ytk)Var(yt)\rho_k = \frac{\mathrm{Cov}(y_t,\ y_{t-k})}{\mathrm{Var}(y_t)}
(1)

yty_t is the value at time tt, Cov\mathrm{Cov} is covariance (how much two things move together) and Var\mathrm{Var} is variance. When ρk\rho_k is near 1, looking kk steps back tells you most of what today looks like. It is a ratio, which says: how much today and the point kk steps back rise and fall together, divided by the series' own spread so the number means the same thing on any scale. Near 0, the point kk steps back tells you nothing about now.

Plot this for k=1,2,3,k=1,2,3,\dots and you have the ACF, where nearly every time-series job begins. Daily retail data spikes at k=7k=7 (day of week); monthly data spikes at k=12k=12. The periodicity is visible at a glance.

Stationarity: betting that the rules stay the same

Every classical method assumes stationarity — that the mean, variance and autocorrelation structure do not depend on time. The reason is simple: a model estimates a rule from the past and applies it to the future, so if the rule changes midway, the estimate was meaningless.

Real series are rarely stationary. A trend moves the mean, so we take a difference.

Δyt=ytyt1\Delta y_t = y_t - y_{t-1}
(2)

That is all it does: replace "the value" with "the change since yesterday". Put in words, Δyt\Delta y_t is a new series answering "how much higher is this step than the one before it?" — a question about level becomes a question about movement. A straight-line trend disappears after one pass, a curved one after two. For an annual cycle you use the seasonal difference ytyt12y_t - y_{t-12}.

Do not overdo it. Differencing too often shaves off real signal and amplifies what noise remains. The rule is "only as many times as it takes to become stationary".

FIG 1Raise the degree and the training points are hit perfectly, but the curve goes wild the moment you step outside. In a time series that "outside" is always the future, and it starts immediately after the training window ends. Fitting the past well guarantees nothing about hitting what comes next

ARIMA: three parts, and the name spells them out

ARIMA is a plain model whose name is simply the initials of its three parts.

AR (autoregression) explains today as a weighted sum of your own past.

yt=c+ϕ1yt1++ϕpytp+εty_t = c + \phi_1 y_{t-1} + \cdots + \phi_p y_{t-p} + \varepsilon_t
(3)

ϕi\phi_i is the weight on the value ii steps back, pp is how far back you look, εt\varepsilon_t is the error and cc a constant. As a sentence it is a recipe which says: today = a baseline, plus some fraction of yesterday, plus some fraction of the day before, and so on, plus whatever luck today brought. The intuition is inertia — "it was high yesterday, so it is high today".

MA (moving average) is a weighted sum of past errors.

yt=μ+εt+θ1εt1++θqεtqy_t = \mu + \varepsilon_t + \theta_1 \varepsilon_{t-1} + \cdots + \theta_q \varepsilon_{t-q}
(4)

μ\mu is the mean and θj\theta_j the weight on the error jj steps back. The same thing in words: today = the usual level + today's luck + part of yesterday's luck still echoing + ..., where "luck" is whatever the model could not account for. The intuition is the tail of a shock — "last week's unexpected dip is still working its way through". Confusingly, this is not the smoothing moving average.

I (integration) is the differencing above: difference dd times, then fit AR and MA. That completes ARIMA(p,d,q)\mathrm{ARIMA}(p,d,q). Give the seasonal component its own set of terms and you get SARIMA(p,d,q)(P,D,Q)s\mathrm{SARIMA}(p,d,q)(P,D,Q)_s, where ss is the period.

The other basic move is decomposition.

What's behind this

§

Members-only from here

371 walkthroughs, 26 textbook chapters, 48 student units and 6 close readings — all included for $4.99/mo, with three new explainers every day. Cancel any time; access runs to the end of the period.

Already a member? Sign in to keep reading

Comments

Sign in to comment