Out-of-Sample Forecasts with Time Series Data

Eric
3 min readMar 18, 2021

We’ll look at some historical housing prices for zipcode 79907 from 1996 to 2018 for our time series analysis. We start off with the assumption that an ARIMA model has been analyzed and stored in the variable model.

original time series data
parameters are statistically significant

The question is, what do you do next, now that you have a model?

Starting with the end in mind, our out-of-sample forecast analysis will produce these results:

forecasting analysis of a time series

How we get there

We’ll start off with showing the full code execution and walk through its major components. You’ll notice there is a DataFrame (df) being used as a parameter in the function below — it has additional information (city, state) that will be used to populate the final table.

original DataFrame from which time series data was taken

Creating forecasts from an ARIMA model (full code)

Read on below to know more about the major components of the function.

Breaking it down

To start, the forecast period needs to be determined. The number of periods to forecast is passed in under the period parameter — in this case, we are using months, as the time series data is in this unit of time.

Next, we will use statsmodels built-in function, forecast(), to predict values over the forecast period and also create a 95% confidence interval.

original time series with forecasts, including 95% confidence interval

Let’s see what this data looks like by plotting the original time series and the out-of-sample forecast.

Visually, the out-of-sample forecast appears to trend upwards.

After visually producing the results, we’ll quantify the predictions via calculating percentage changes in the forecasts.

As an added step, the initial investment of purchasing a property in this zipcode will be calculated using market estimates.

Finally, we create the summary table that provides the out-of-sample forecast percentages and zipcode information.

summary table for out-of-sample forecasts

There you have it

This is one method to produce out-of-sample forecasts and view the confidence interval in which the prediction occurs, as well. As a final note, here is the full function in its entirety:

--

--

Eric

How do you put out a fire in your office wastebasket? First, set fire to more wastebaskets to get a larger sample size. Setting wastebasket fires since 2020.