Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Forecasting with Moving Averages | Section
Forecasting With Classical Models

bookForecasting with Moving Averages

Sveip for å vise menyen

To forecast future values in a time series, moving averages offer a simple yet effective approach. You can use a simple moving average (SMA) to predict the next value by averaging the most recent NN observations. The process for one-step-ahead forecasting with SMA involves the following steps:

  1. Choose the window size NN, which determines how many past values you will average;
  2. For each time point tt, calculate the average of the previous NN values: (xtN+1,xtN+2,...,xtx_{t-N+1}, x_{t-N+2}, ..., x_t);
  3. Use this average as the forecast for the next time point (t+1t+1);
  4. Slide the window forward by one period and repeat the process for each subsequent forecast.

While this method is easy to implement and understand, it has several limitations. Moving averages assume that recent values are the best predictors of the next value, which may not hold if there are trends or seasonality in the data. Furthermore, SMAs give equal weight to all NN values, potentially ignoring the relevance of more recent data. As a result, forecasts may lag behind actual changes, especially in volatile or non-stationary time series.

123456789101112131415161718
import pandas as pd # Example time series data data = [12, 14, 15, 16, 15, 17, 18, 20, 19, 21] N = 3 # Window size for SMA # Create a pandas Series ts = pd.Series(data) # Calculate the Simple Moving Average (SMA) sma = ts.rolling(window=N).mean() # Forecast the next value using the last N values last_n_values = ts[-N:] forecast = last_n_values.mean() print(f"Last {N} values: {list(last_n_values)}") print(f"Forecast for next value using SMA: {forecast:.2f}")
copy
question mark

Which of the following is a limitation of using simple moving averages for forecasting?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 4

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Seksjon 1. Kapittel 4
some-alt