Forecasting: sales next month
Twelve months of sales, and one question: what comes next? This lesson shows how a model reads time — what lags and horizon actually mean, and why forecasts get fuzzier the further out they go.
Why this is not plain regression
In lessons 2 and 3, shuffling the rows changed nothing — each house or customer stood on its own. A sales history is different: the order IS the information. Forecasting is prediction for data measured over time, where each value grows out of the ones before it.
Our data: monthly sales for one year, in thousands of SAR.
| Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 100 | 110 | 105 | 120 | 130 | 125 | 140 | 150 | 145 | 160 | 170 | 165 |
Look at it for a second: sales drift upward across the year, with a small dip every third month. A good forecaster should pick up both.
Lags: the recent past as features
A forecaster cannot use "size" or "tickets" — its only raw material is the series itself. So it manufactures features from the recent past: lags. With 3 lags, each month is predicted from the three months before it. That turns the series into ordinary training rows:
| Inputs (the 3 lags) | Answer to learn |
|---|---|
| Jun 125 · Jul 140 · Aug 150 | Sep 145 |
| Jul 140 · Aug 150 · Sep 145 | Oct 160 |
| Aug 150 · Sep 145 · Oct 160 | Nov 170 |
| Sep 145 · Oct 160 · Nov 170 | Dec 165 |
Every row is a mini-exam: "given these three months, guess the fourth." From here, training works exactly like lesson 1 — guess, measure, adjust — and any regression-style model family can compete.
Horizon: how far ahead, one step at a time
The horizon is how many steps into the future you ask for. To forecast three months, the model predicts January from [Oct, Nov, Dec] — then predicts February using its own January guess as one of the inputs, and March using two of its own guesses.
Each step feeds on the last step's guess, so small errors compound — like a rumor retold three times. That is why Bayanii shows a shaded uncertainty band around forecasts, and why the band widens with every step: month 1 is a prediction, month 6 is an educated squint.
Trend and seasonality, by eye
Two patterns hide in almost every business series. The trend: our sales climb from 100 to 165 over the year — growth the model should extend, not ignore. The seasonality: that every-third-month dip repeats on a schedule, like Ramadan hours, summer holidays, or end-of-quarter pushes. Lags let a model catch both, because "three months ago" carries the seasonal echo.
What can go wrong with time
Leakage wears a special disguise here: information from the future. If a model is graded on months it effectively already saw — or a feature column contains values recorded after the month it describes — the score is fiction. Bayanii always tests forecasters on the END of the series, never on a random shuffle, so the exam is genuinely "the future".
Gaps and irregular timestamps: a missing March, or data jumping between daily and monthly, breaks the "each row follows the last" assumption lags depend on. Bayanii's dataset checks flag these before training — lesson 6 walks through what each finding means.
How forecasts are scored
Forecast errors are usually judged as percentages — "off by 6% in a typical month" — using MAPE and its steadier cousin sMAPE, alongside the MAE/RMSE you already know from lesson 2. The next lesson works every one of these through with real numbers.
This lesson describes Bayanii's real pipeline in simplified terms. It is updated by hand when the pipeline changes, so wording may occasionally lag the code.