AI & Machine Learning Master Course — 142. Naive, seasonal, and moving-average baselines
Smartyfy AI & Machine Learning Master Course
Course ID: smartyfy-ai-ml-master-200
Lesson 142: Naive, seasonal, and moving-average baselines
Prerequisites: Lesson 141. Learning outcome: Construct forecasting baselines that match seasonality and operational timing.
A baseline should match the time structure
A forecasting baseline is a serious reference, not a weak model chosen to make another method look good. Persistence can be difficult to beat for slowly changing data. Seasonal repetition can be strong when daily, weekly, or annual patterns are stable. A learned model should demonstrate value relative to an appropriate simple rule under the same information boundary.
The naive forecast repeats the latest available observation for every future horizon. It assumes that the most recent level is a useful anchor. The seasonal-naive forecast repeats the latest observed value from the corresponding seasonal position. A seven-day seasonal pattern uses the previous matching day of the week, rather than yesterday, for a daily forecast.
The choice depends on the process. A weekly rule is inappropriate for a series without a meaningful weekly cycle, and persistence may lag behind a strong trend. Inspect the series and use development evaluation to choose credible baselines before final comparison.
Distinguish a rolling average from a complete forecast rule
A trailing moving average summarizes the most recent m available observations. To turn it into a forecast, specify how that summary is used for future horizons. In this lesson, the last seven training values are averaged once and the resulting constant is used for all seven future targets from one origin.
That fixed-origin rule is different from recomputing the average after each new actual observation arrives. It is also different from recursively appending predicted values and recomputing the average. All three can be defined, but mixing them inside one reported experiment changes the information available at each horizon.
A larger averaging window smooths more short-term variation but can respond more slowly to level changes. A smaller window reacts faster but can be noisier. Choose the window using earlier development periods, and remember that a centered average uses future values relative to its center and is not a valid real-time feature at that point.
CPU lab: forecast one synthetic weekly cycle
The fictional series repeats the seven-position pattern [20,22,24,23,21,18,17] exactly. The first twenty-eight observations form four training cycles; the next seven are held out as one future cycle. All forecasts are issued after the training segment, without updating on test outcomes.
Naive persistence predicts seventeen for every future position and has mean absolute error 3.714286. Seasonal naive copies the final observed cycle and has zero error because the generator repeats it exactly. The trailing-seven mean is 20.714286, used as a constant forecast, with MAE approximately 2.040816.
The perfect seasonal result is a consequence of the deliberately deterministic fixture. It does not show that seasonal naive will be perfect on noisy, trending, or shifting real demand. The code checks the predictions and makes the common information cutoff explicit. NumPy performs all computation locally.
import numpy as np
pattern=np.array([0,2,4,3,1,-2,-3],float)
y=20+np.tile(pattern,5)
train,test=y[:28],y[28:]
forecasts={'naive':np.full(7,train[-1]),
'seasonal_naive':train[-7:].copy(),
'moving_average_7':np.full(7,train[-7:].mean())}
for name,pred in forecasts.items():
print(name,'forecast',pred.tolist(),'MAE',round(float(np.mean(abs(pred-test))),6))
assert np.array_equal(forecasts['seasonal_naive'],test)
assert np.all(forecasts['naive']==17)
assert np.all(forecasts['moving_average_7']==train[-7:].mean())
Baseline results
| Rule | Prediction pattern | MAE, units |
|---|---|---|
| Naive | Constant 17 | 3.714286 |
| Seasonal naive | Repeat last cycle | 0 |
| Trailing-seven mean | Constant 20.714286 | 2.040816 |
Compare errors using suitable units
Mean absolute error averages the absolute difference between forecasts and outcomes and retains the target’s units. Root mean squared error also retains units but gives larger errors more weight. Choose a measure connected to the task rather than reporting whichever makes a favored model look strongest.
Percentage errors require care near zero and with values where percentage interpretation is inappropriate. A zero-demand day can make ordinary percentage error undefined. Scaled errors can support comparisons across differently sized series, but their scale must be computed from permitted training data with a stated baseline and nonzero denominator.
Also inspect horizon-specific errors. A method that is good tomorrow may deteriorate over the next week. Averaging every horizon into one score can conceal that pattern. If the decision concerns a seven-day total, evaluate the total as well; accurate daily values and accurate totals are related but distinct objectives.
Extend the fixture without invalidating the comparison
Add noise, a trend, or a level shift to create new development experiments, keeping test outcomes unavailable to the forecasting rules. Predict how each baseline should respond before running it. Seasonal repetition may track a cycle while missing a new level; a moving average may smooth noise while lagging a shift.
Do not choose the window size or seasonal period by repeatedly checking the final test score. Record candidate rules, select them on historical development origins, and then freeze the chosen baseline for the final comparison. A baseline can be tuned and evaluated with the same discipline as a complex model.
Preserve the forecasts, not just the aggregate error. A table of origin, horizon, target, and prediction makes it possible to discover accidental test updates or shifted alignment. If a forecast vector is off by one seasonal position, the code can run perfectly while evaluating the wrong task.
Four practice questions with worked answers
Practice 1
The last observed values are [10,12,14]. What are a naive next-step forecast and a trailing-three mean forecast?
Answer: Naive predicts the latest value, fourteen. The trailing mean predicts (10+12+14)/3=12. The two rules express different assumptions about whether the last level or recent average is most useful.
Practice 2
A weekly seasonal-naive model forecasts next Monday. Which observation is reused?
Answer: The latest available Monday under the forecast’s information contract. It does not simply use the latest Sunday unless the chosen rule is ordinary naive persistence.
Practice 3
Errors are [−2,1,3]. Compute MAE.
Answer: Take absolute values [2,1,3], sum to six, and divide by three. MAE is two target units. Signed errors would average differently because positive and negative errors can cancel.
Practice 4
Why does the seasonal baseline have zero error in this lab?
Answer: The data generator repeats the same seven-position pattern exactly. The test cycle matches the final training cycle by construction. This is a mechanics check, not a real-world performance guarantee.
Five multiple-choice questions
Question 1
What does naive forecasting repeat?
- A. The latest available observation.
- B. The value at the same seasonal position regardless of whether it is available.
- C. The average of future realized values.
Correct: A. Naive persistence uses the latest known value. Future values and unavailable seasonal observations violate that rule.
Question 2
Which moving-average forecast is executed here?
- A. A trailing mean recomputed recursively after appending each predicted value.
- B. A trailing mean recomputed after each newly available actual observation for the next issue.
- C. A fixed trailing-seven mean repeated across the seven future horizons.
Correct: C. The lab uses one forecast origin and one training-only mean. The alternatives describe different update rules: recursive predicted history or successive forecast origins.
Question 3
Why is seasonal naive perfect in the fixture?
- A. Its predictions are updated from each realized test value before scoring.
- B. Seasonal naive is universally optimal whenever the period is seven.
- C. The held-out cycle repeats the same deterministic pattern.
Correct: C. Exact repetition explains the zero error. No test updating occurs, and the result does not establish universal optimality.
Question 4
What problem can ordinary percentage error have at a zero actual value?
- A. It automatically ignores that case without affecting the evaluation definition.
- B. Division by zero makes the usual ratio undefined.
- C. It becomes identical to absolute error in every case.
Correct: B. A zero denominator needs an explicit metric policy. Silent omission changes the reported sample and should not be assumed.
Question 5
Where should a moving-average window be selected?
- A. The window that uses the greatest number of future observations.
- B. Earlier development periods or rolling validation origins.
- C. The final test period after comparing every possible window.
Correct: B. Window choice is model selection. Final-test feedback and future information compromise an untouched evaluation.
Common pitfalls
Avoid weak or mismatched baselines, unstated moving-average horizon rules, percentage errors at zero without a policy, and perfect synthetic scores presented as operational evidence. Check seasonal alignment and forecast cutoffs.
Summary
Naive, seasonal-naive, and trailing-average rules provide transparent forecasts with different assumptions. A defensible comparison uses the same origin and targets, records horizon behavior, and keeps baseline selection outside the final test.