Moving Averages
Explore the concept of moving averages in time series forecasting, including the rolling mean and moving average model MA(n). Understand how to calculate simple moving averages using Python's pandas rolling method and apply the MA(n) model with the statsmodels ARIMA function to forecast data. This lesson helps you grasp smoothing techniques and build basic forecasting models effectively.
We'll cover the following...
Understanding moving averages
Moving averages can refer to two different things in time series forecasting:
A simpler concept, also known as a rolling mean.
The moving average model, also known as MA(n).
The rolling mean is the average of the value we are looking at calculated over a certain period of time. That average is updated according to the period, so it's always relative.
Using weather data as an example, we could look at the average temperature over the past thirty days. If we do that for every day in our data series, we would get the moving average over thirty days for the whole period. Let's see how to do this in practice and how we can use this to make forecasts.
Calculating simple moving averages
Using our Seattle weather data as an example, we can plot the original time series with the moving average to see how it behaves. In pandas, we can do this with the rolling() method.
Notice how the moving average over thirty days smooths out our time series? That's because over thirty days, there are warmer days and colder days, and they tend to balance each other out when we take their average.
Forecasting with moving averages
To use moving averages for forecasting, we usually apply the second version of the moving average concept, which we will call an MA(n) model.