concept

Seasonal naive forecast

Repeat the last observed cycle to predict a fixed-origin horizon. Requires a positive integer period no longer than history and a nonnegative integer horizon. No future observations are read.

Formal Syntax & Structure

artificial-intelligence syntaxartificial-intelligence
seasonal_forecast(history, period, horizon)

Working Example

Example Snippetartificial-intelligence
def seasonal_forecast(history, period, horizon):    if type(period) is not int or not 1 <= period <= len(history):        raise ValueError("period must fit observed history")    if type(horizon) is not int or horizon < 0:        raise ValueError("nonnegative integer horizon required")    cycle = history[-period:]    return [cycle[i % period] for i in range(horizon)]
history = [10, 20, 11, 21]print(seasonal_forecast(history, 1, 2))print(seasonal_forecast(history, 2, 2))print(seasonal_forecast(history, 2, 5))