# Autoregression

Learn how to use autoregression to forecast with time series data.

We'll cover the following

## Understanding autoregression

Autoregression, as the name suggests, is a regression of a value over itself at some other moment. It means we look at the model like this:

$x_t=\alpha+\beta_1x_{t-1}+...+\beta_n x_{t-n}+\epsilon$

Where:

• $x_t$ is the variable we want to predict at a time, $t$,$x_{t-1}$ is that same variable at time $t-1$, and so on.

• $\alpha$ is a constant.

• $\beta_1$ is the coefficient used for $x_{t-1}$, $\beta_2$ is the coefficient used for $x_{t-2}$, and so on.

• $\epsilon$ is the error term.

Intuitively, that model works almost as a weighted average between past observations, and the $\beta$ coefficients will give the weights for each time lag.

How far does $n$ go? That is up to us to choose depending on how far back in time we want to go to make our forecasts. We define an AR model as AR(n) depending on the value we want to set for $n$. So an AR(2) model will forecast a value based on the two previous values.

## Forecasting with autoregression

Fortunately, we don't have to do that regression on our own. We can use the same Python function, ARIMA, which we used to calculate the MA(n) model. To implement AR(2), let us set the MA parameter to zero and the AR parameter to two, in the ARIMA function.

Get hands-on with 1200+ tech skills courses.