PeaBox Lab › PeaLang › Learn › Chapter 18 › Lesson 5

Part III — Advanced Systems · Chapter 18 · Lesson 5 of 7 · 7 min read

Lesson 5: Trend, Moving-Average, and Exponential-Smoothing Baselines

Lesson level: Advanced

Purpose: Build simple, transparent forecasts that are fast to compute, easy to explain, and surprisingly hard to beat — and use them as the benchmark every more complex model must clear.

Learning objectives

By the end of this lesson you will be able to:

5.1 Why baselines come first

A baseline answers a question every stakeholder will eventually ask: is the sophisticated model actually better than something simple? In published forecasting competitions and in practice, simple methods frequently match or beat complex ones on short horizons. A model that cannot beat a seasonal naive forecast in backtests is not ready, however elegant it is.

Baselines are also useful in production. They are cheap, deterministic, and robust, so they make good fall-backs when a complex model fails, when data for a new product is short, or when a forecast must be explained line by line.

5.2 Naive and seasonal naive

Illustrative listing.

def seasonal_naive(train, dates, period=7):
    last = train.sort("date").tail(period)
    pattern = last.column("revenue").to_list()
    return [pattern[i % period] for i in range(len(dates))]

Check that the pattern is aligned to the calendar: if the training data ends on a Wednesday, the first forecast day is Thursday and must use last Thursday's value. Index the pattern by weekday rather than by position when there is any chance of gaps.

5.3 Linear trend

A linear trend fits ŷ = a + b × t by least squares and extends the line into the future. It captures steady growth or decline, and its slope is easy to communicate ("about 120 more orders per month").

def fit_trend(train):
    t = list(range(train.height))
    y = train.column("revenue").to_list()
    n = len(t)
    t_mean = sum(t) / n
    y_mean = sum(y) / n
    b = sum((ti - t_mean) * (yi - y_mean) for ti, yi in zip(t, y)) \
        / sum((ti - t_mean) ** 2 for ti in t)
    a = y_mean - b * t_mean
    return a, b, n

def predict_trend(model, horizon):
    a, b, n = model
    return [a + b * (n + h) for h in range(horizon)]

Linear trends are dangerous over long horizons. Growth slows, markets saturate, and a straight line will eventually predict negative demand or impossible growth. Fit trends on a recent window, combine them with seasonality, and limit the horizon over which they are trusted. Fitting on log values gives a constant-percentage-growth trend, which is often more realistic for business series.

5.4 Moving-average forecast

A moving-average forecast predicts every future value as the mean of the last k observations. It smooths noise well, but it lags behind a trend by roughly (k − 1) / 2 periods and ignores seasonality unless k is a whole number of seasons. Use it for stable, non-seasonal series, or combine it with a seasonal index: deseasonalize, average, then reapply the seasonal factor for each forecast day.

5.5 Simple exponential smoothing

Simple exponential smoothing (SES) applies the EWMA from Lesson 2 as a forecaster. The final smoothed level becomes the forecast for every future period:

def ses(values, alpha):
    level = values[0]
    for y in values[1:]:
        level = alpha * y + (1 - alpha) * level
    return level

def fit_ses(train, grid=(0.05, 0.1, 0.2, 0.3, 0.5)):
    y = train.column("revenue").to_list()
    best = None
    for a in grid:
        level, sse = y[0], 0.0
        for v in y[1:]:
            sse += (v - level) ** 2          # one-step-ahead error
            level = a * v + (1 - a) * level
        if best is None or sse < best[1]:
            best = (a, sse, level)
    return {"alpha": best[0], "level": best[2]}

Choose α by minimizing one-step-ahead error on the training data, as above, and check the result in the backtest. A chosen α close to 1 says the series is almost a random walk (naive is nearly as good); an α close to 0 says it is almost constant (mean is nearly as good).

5.6 Holt and Holt-Winters

SES produces a flat forecast. Holt's method adds a smoothed trend term with its own factor β, so the forecast is a line: ŷt+h = levelt + h × trendt. A damped variant shrinks the trend for longer horizons with a factor φ slightly below 1, which usually performs better because trends rarely continue indefinitely.

Holt-Winters adds a seasonal term with factor γ and a period m, in either additive or multiplicative form (the same choice as in Lesson 3). It is a strong, widely used baseline for regular seasonal series such as daily retail sales with a weekly cycle.

MethodParametersCapturesForecast shape
SESαLevelFlat
Holtα, βLevel and trendStraight line
Damped Holtα, β, φLevel and fading trendCurve that flattens
Holt-Wintersα, β, γ, mLevel, trend, and seasonalityRepeating seasonal pattern on a trend

Initial values for level, trend, and seasonal indices matter for short series. A common approach uses the first one or two seasons: the mean of the first season for the level, the average change between the first two seasons for the trend, and the first season's deviations from its mean for the seasonal indices. Record the initialization rule with the model.

5.7 Comparing baselines

Run every baseline through the same backtesting harness, with the same origins, horizon, and metrics. Present the results as one table with a row per method and columns for WAPE, MASE, and bias, overall and for selected horizons. Then apply a simple decision rule: adopt the simplest method whose error is within a small tolerance of the best. Simplicity is worth something: it is easier to explain, cheaper to run, and less likely to break.

Common mistakes

Guided practice

Hands-on lab: A baseline leaderboard

Review questions

Applied challenge

A call centre forecasts calls per half-hour for staffing two weeks ahead. Calls have a daily and a weekly pattern and grow about 8% a year. Build and backtest at least four baselines, including one that handles both seasonal cycles (for example, a seasonal naive on the same half-hour and weekday combined with a damped trend). Recommend one method and state the expected error in agents per shift, not only in percentages.

Lesson summary

Naive, seasonal naive, trend, moving-average, and exponential-smoothing forecasts are fast, transparent, and often hard to beat. Fit their parameters on training data, initialize them consistently, compare them in the same backtest, and adopt the simplest method that performs close to the best. Every later model must justify itself against this leaderboard.

Transition to Lesson 6

A single number per day hides two things the business needs: how uncertain the forecast is, and how it varies across stores or products. Lesson 6 scales forecasts across groups, adds confidence bands, and shapes output for charts.

Lesson status: Ready for review.

← Previous Next →